#Loading Libraries
library(GGally)
## Loading required package: ggplot2
## Registered S3 method overwritten by 'GGally':
## method from
## +.gg ggplot2
library(boot)
library(ggplot2)
library(tidyverse)
## ── Attaching packages
## ───────────────────────────────────────
## tidyverse 1.3.2 ──
## ✔ tibble 3.1.8 ✔ dplyr 1.0.10
## ✔ tidyr 1.2.1 ✔ stringr 1.5.0
## ✔ readr 2.1.3 ✔ forcats 0.5.2
## ✔ purrr 1.0.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(lmboot)
## Warning: package 'lmboot' was built under R version 4.2.3
library(caret)
## Loading required package: lattice
##
## Attaching package: 'lattice'
##
## The following object is masked from 'package:boot':
##
## melanoma
##
##
## Attaching package: 'caret'
##
## The following object is masked from 'package:purrr':
##
## lift
library(naniar)
library(utils)
library(stats)
library(corrplot)
## Warning: package 'corrplot' was built under R version 4.2.3
## corrplot 0.92 loaded
library(ISLR)
## Warning: package 'ISLR' was built under R version 4.2.3
library(car)
## Loading required package: carData
##
## Attaching package: 'car'
##
## The following object is masked from 'package:dplyr':
##
## recode
##
## The following object is masked from 'package:purrr':
##
## some
##
## The following object is masked from 'package:boot':
##
## logit
library(olsrr)
## Warning: package 'olsrr' was built under R version 4.2.3
##
## Attaching package: 'olsrr'
##
## The following object is masked from 'package:datasets':
##
## rivers
##Reading in Dataset
life = read.csv('https://github.com/athibeaux/MSDS-DS6372/raw/main/Life_Expectancy.csv')
ggplot(data = life) + geom_point(mapping = aes(x = GDP, y = Life.expectancy))
## Warning: Removed 453 rows containing missing values (`geom_point()`).
##Upon looking at the graph of the original data set, it appears that
there needs to be a log transformation on the X or the GDP as we are
interested in seeing the relation between Life Expenctancy and GDP.
##Checking Data Types
str(life)
## 'data.frame': 2938 obs. of 22 variables:
## $ Country : chr "Afghanistan" "Afghanistan" "Afghanistan" "Afghanistan" ...
## $ Year : int 2015 2014 2013 2012 2011 2010 2009 2008 2007 2006 ...
## $ Status : chr "Developing" "Developing" "Developing" "Developing" ...
## $ Life.expectancy : num 65 59.9 59.9 59.5 59.2 58.8 58.6 58.1 57.5 57.3 ...
## $ Adult.Mortality : int 263 271 268 272 275 279 281 287 295 295 ...
## $ infant.deaths : int 62 64 66 69 71 74 77 80 82 84 ...
## $ Alcohol : num 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.03 0.02 0.03 ...
## $ percentage.expenditure : num 71.3 73.5 73.2 78.2 7.1 ...
## $ Hepatitis.B : int 65 62 64 67 68 66 63 64 63 64 ...
## $ Measles : int 1154 492 430 2787 3013 1989 2861 1599 1141 1990 ...
## $ BMI : num 19.1 18.6 18.1 17.6 17.2 16.7 16.2 15.7 15.2 14.7 ...
## $ under.five.deaths : int 83 86 89 93 97 102 106 110 113 116 ...
## $ Polio : int 6 58 62 67 68 66 63 64 63 58 ...
## $ Total.expenditure : num 8.16 8.18 8.13 8.52 7.87 9.2 9.42 8.33 6.73 7.43 ...
## $ Diphtheria : int 65 62 64 67 68 66 63 64 63 58 ...
## $ HIV.AIDS : num 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 ...
## $ GDP : num 584.3 612.7 631.7 670 63.5 ...
## $ Population : num 33736494 327582 31731688 3696958 2978599 ...
## $ thinness..1.19.years : num 17.2 17.5 17.7 17.9 18.2 18.4 18.6 18.8 19 19.2 ...
## $ thinness.5.9.years : num 17.3 17.5 17.7 18 18.2 18.4 18.7 18.9 19.1 19.3 ...
## $ Income.composition.of.resources: num 0.479 0.476 0.47 0.463 0.454 0.448 0.434 0.433 0.415 0.405 ...
## $ Schooling : num 10.1 10 9.9 9.8 9.5 9.2 8.9 8.7 8.4 8.1 ...
vis_miss(life)
## Warning: `gather_()` was deprecated in tidyr 1.2.0.
## ℹ Please use `gather()` instead.
## ℹ The deprecated feature was likely used in the visdat package.
## Please report the issue at <]8;;https://github.com/ropensci/visdat/issueshttps://github.com/ropensci/visdat/issues]8;;>.
dim(life)
## [1] 2938 22
#Imputing using Median
#GDP 15% [17] keep GDP to have it Imputed even if quite high percentage, assuming it is crucial to predicting Life.expectancy as richer countries have better health access/Medicine and tech. The numbers appear to be GDP per capita which helps as it addresses GDP/Population. GDP per Capita and Population would be too closely related and prob attribute to covariance.
#Adjusting text angle to vis_miss
imputeMedian= preProcess(life[,-c(1:4,9)],method="medianImpute") #predictors 1:3, 9, 17 and response is 4
cleandataMedian = predict(imputeMedian,newdata=life)
dim(cleandataMedian)
## [1] 2938 22
vis_miss(cleandataMedian) + theme(axis.text.x = element_text(angle = 90, hjust = 0))
#Literature says that over 10% missing data can contribute to bias
#HepatitsB [9] at 19% , Population 22% [18].
#Removing columns 9 and 18
cleandataMedian = cleandataMedian[,-c(18,9)]
vis_miss(cleandataMedian) + theme(axis.text.x = element_text(angle = 90, hjust = 0))
#removing last NA
cleandataMedian = na.omit(cleandataMedian)
vis_miss(cleandataMedian) + theme(axis.text.x = element_text(angle = 90, hjust = 0))
Splitting the data
set.seed(1234)
trainIndex<-createDataPartition(cleandataMedian$Life.expectancy,p=.8,list=F) #p: proportion of data in train
training<-cleandataMedian[trainIndex,]
validate<-cleandataMedian[-trainIndex,]
Before and after log transforming GDP, with cleandataMedian:
ggplot(data = training) + geom_point(mapping = aes(x = GDP, y = Life.expectancy))
#Log transformation on GDP
ggplot(data = training) + geom_point(mapping = aes(x = log(GDP), y = Life.expectancy))
##Correlation Matrix:
cor <- cor(training[,c(4,5:20)])
corrplot(cor, method = "square", tl.srt = 50, tl.col = "black", tl.cex = 0.6, title = "Correlation of Variables", mar=c(0,0,1,0))
GGPairs:
#commented out for knitting
#ggpairs(training[,4:20])
Create categorical variable from year:
summary(training$Year)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2000 2004 2008 2008 2011 2015
#Labeled the breaks in years into 2 year buckets
training$DualYears <- cut(as.numeric(training$Year), breaks=c(0, 2001, 2003, 2005, 2007, 2009, 2011, 2013, 2015), labels=c('2000-2001', '2002-2003', '2004-2005', '2006-2007', '2008-2009', '2010-2011','2012-2013','2014-2015'))
training %>% ggplot() + geom_bar(aes(x = DualYears))
summary(training$DualYears)
## 2000-2001 2002-2003 2004-2005 2006-2007 2008-2009 2010-2011 2012-2013 2014-2015
## 278 298 302 288 302 296 291 289
Full Model
full.model <- lm(Life.expectancy~Status + Adult.Mortality + infant.deaths +
Alcohol + percentage.expenditure + Measles + BMI +
under.five.deaths + Polio + Total.expenditure +
Diphtheria + HIV.AIDS + log(GDP) +
thinness..1.19.years + thinness.5.9.years +
Income.composition.of.resources + Schooling, training)
summary(full.model)
##
## Call:
## lm(formula = Life.expectancy ~ Status + Adult.Mortality + infant.deaths +
## Alcohol + percentage.expenditure + Measles + BMI + under.five.deaths +
## Polio + Total.expenditure + Diphtheria + HIV.AIDS + log(GDP) +
## thinness..1.19.years + thinness.5.9.years + Income.composition.of.resources +
## Schooling, data = training)
##
## Residuals:
## Min 1Q Median 3Q Max
## -20.7738 -2.1414 0.0039 2.4033 16.0974
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 5.387e+01 7.836e-01 68.743 < 2e-16 ***
## StatusDeveloping -1.622e+00 2.978e-01 -5.446 5.70e-08 ***
## Adult.Mortality -2.040e-02 8.881e-04 -22.969 < 2e-16 ***
## infant.deaths 1.006e-01 9.196e-03 10.944 < 2e-16 ***
## Alcohol 4.337e-02 2.924e-02 1.484 0.1381
## percentage.expenditure 1.292e-04 5.552e-05 2.327 0.0201 *
## Measles -1.809e-05 8.442e-06 -2.143 0.0322 *
## BMI 4.194e-02 5.581e-03 7.514 8.15e-14 ***
## under.five.deaths -7.508e-02 6.791e-03 -11.056 < 2e-16 ***
## Polio 2.313e-02 4.947e-03 4.676 3.10e-06 ***
## Total.expenditure 7.527e-02 3.780e-02 1.991 0.0466 *
## Diphtheria 3.646e-02 4.981e-03 7.319 3.41e-13 ***
## HIV.AIDS -4.456e-01 1.984e-02 -22.460 < 2e-16 ***
## log(GDP) 3.807e-01 6.925e-02 5.497 4.28e-08 ***
## thinness..1.19.years -1.105e-01 5.534e-02 -1.997 0.0459 *
## thinness.5.9.years 4.933e-02 5.463e-02 0.903 0.3666
## Income.composition.of.resources 5.356e+00 7.276e-01 7.362 2.50e-13 ***
## Schooling 6.498e-01 4.849e-02 13.399 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.036 on 2326 degrees of freedom
## Multiple R-squared: 0.8209, Adjusted R-squared: 0.8196
## F-statistic: 627.2 on 17 and 2326 DF, p-value: < 2.2e-16
plot(full.model)
vif(full.model)
## Status Adult.Mortality
## 1.838844 1.780353
## infant.deaths Alcohol
## 169.796757 1.852065
## percentage.expenditure Measles
## 1.662750 1.413270
## BMI under.five.deaths
## 1.759970 172.441705
## Polio Total.expenditure
## 1.990509 1.193206
## Diphtheria HIV.AIDS
## 2.026188 1.470530
## log(GDP) thinness..1.19.years
## 2.064070 8.502120
## thinness.5.9.years Income.composition.of.resources
## 8.625148 3.152621
## Schooling
## 3.542768
Fitting a preliminary model of non-redundant variables
prelim.model <- lm(Life.expectancy~Alcohol + Measles + BMI +
under.five.deaths + Polio + Total.expenditure +
Diphtheria + HIV.AIDS + log(GDP) +
thinness..1.19.years +
Income.composition.of.resources + Schooling, training)
summary(prelim.model)
##
## Call:
## lm(formula = Life.expectancy ~ Alcohol + Measles + BMI + under.five.deaths +
## Polio + Total.expenditure + Diphtheria + HIV.AIDS + log(GDP) +
## thinness..1.19.years + Income.composition.of.resources +
## Schooling, data = training)
##
## Residuals:
## Min 1Q Median 3Q Max
## -27.8833 -2.5900 0.1524 2.6914 19.4391
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.256e+01 6.593e-01 64.552 < 2e-16 ***
## Alcohol 3.571e-02 3.074e-02 1.162 0.245540
## Measles -1.125e-05 9.646e-06 -1.166 0.243721
## BMI 5.243e-02 6.327e-03 8.287 < 2e-16 ***
## under.five.deaths -6.712e-04 7.815e-04 -0.859 0.390553
## Polio 2.883e-02 5.682e-03 5.075 4.19e-07 ***
## Total.expenditure 1.532e-01 4.289e-02 3.571 0.000362 ***
## Diphtheria 4.710e-02 5.685e-03 8.285 < 2e-16 ***
## HIV.AIDS -6.889e-01 1.996e-02 -34.516 < 2e-16 ***
## log(GDP) 5.889e-01 7.086e-02 8.311 < 2e-16 ***
## thinness..1.19.years -8.489e-02 3.047e-02 -2.786 0.005385 **
## Income.composition.of.resources 8.038e+00 8.268e-01 9.722 < 2e-16 ***
## Schooling 7.919e-01 5.543e-02 14.286 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.642 on 2331 degrees of freedom
## Multiple R-squared: 0.7625, Adjusted R-squared: 0.7613
## F-statistic: 623.7 on 12 and 2331 DF, p-value: < 2.2e-16
plot(prelim.model)
vif(prelim.model)
## Alcohol Measles
## 1.547310 1.394134
## BMI under.five.deaths
## 1.709194 1.725861
## Polio Total.expenditure
## 1.984334 1.160591
## Diphtheria HIV.AIDS
## 1.994255 1.124632
## log(GDP) thinness..1.19.years
## 1.633008 1.947947
## Income.composition.of.resources Schooling
## 3.076060 3.498226
Feature Selection Tools: Penalized Regression
# Penalized Regression
#Setting kfold parameters
fitControl<-trainControl(method="repeatedcv",number=5,repeats=1)
#Fitting glmnet
set.seed(1234)
glmnet.fit<-train(Life.expectancy~infant.deaths + Alcohol +
percentage.expenditure + Measles + BMI +
under.five.deaths + Polio + Total.expenditure +
Diphtheria + HIV.AIDS + log(GDP) +
thinness..1.19.years + thinness.5.9.years +
Income.composition.of.resources + Schooling,
data=training,
method="glmnet",
trControl=fitControl
)
glmnet.fit
## glmnet
##
## 2344 samples
## 15 predictor
##
## No pre-processing
## Resampling: Cross-Validated (5 fold, repeated 1 times)
## Summary of sample sizes: 1875, 1877, 1874, 1875, 1875
## Resampling results across tuning parameters:
##
## alpha lambda RMSE Rsquared MAE
## 0.10 0.01359526 4.546733 0.7715121 3.428469
## 0.10 0.13595255 4.617190 0.7645704 3.477897
## 0.10 1.35952554 4.677957 0.7611292 3.543112
## 0.55 0.01359526 4.546678 0.7715357 3.427825
## 0.55 0.13595255 4.642083 0.7621296 3.494318
## 0.55 1.35952554 4.837724 0.7583217 3.646672
## 1.00 0.01359526 4.547465 0.7714789 3.427827
## 1.00 0.13595255 4.645565 0.7619759 3.493011
## 1.00 1.35952554 5.132045 0.7483316 3.890102
##
## RMSE was used to select the optimal model using the smallest value.
## The final values used for the model were alpha = 0.55 and lambda = 0.01359526.
plot(glmnet.fit)
#Investigating coefficients
opt.pen<-glmnet.fit$finalModel$lambdaOpt #penalty term
coef(glmnet.fit$finalModel,opt.pen)
## 16 x 1 sparse Matrix of class "dgCMatrix"
## s1
## (Intercept) 4.460994e+01
## infant.deaths 7.072859e-02
## Alcohol 4.933926e-02
## percentage.expenditure 2.592483e-04
## Measles -6.563182e-06
## BMI 5.356624e-02
## under.five.deaths -5.267115e-02
## Polio 2.688020e-02
## Total.expenditure 1.322282e-01
## Diphtheria 4.334536e-02
## HIV.AIDS -6.760276e-01
## log(GDP) 4.439098e-01
## thinness..1.19.years -9.170910e-02
## thinness.5.9.years .
## Income.composition.of.resources 7.354446e+00
## Schooling 7.755679e-01
glmnet.fit.model <-lm(Life.expectancy~infant.deaths + Alcohol +
percentage.expenditure + Measles + BMI +
under.five.deaths + Polio + Total.expenditure +
Diphtheria + HIV.AIDS + log(GDP) +
thinness..1.19.years +
Income.composition.of.resources + Schooling,
data=training)
plot(glmnet.fit.model)
#Lets force a LASSO model and add complexity
set.seed(1234)
glmnet.fit2<-train(Life.expectancy~infant.deaths + Alcohol +
percentage.expenditure + Measles + BMI +
under.five.deaths + poly(Polio,2) + Total.expenditure +
Diphtheria + HIV.AIDS + log(GDP) +
thinness..1.19.years + thinness.5.9.years +
Income.composition.of.resources + Schooling,
data=training,
method="glmnet",
trControl=fitControl,
tuneGrid=expand.grid(data.frame(alpha=1,lambda=seq(0,.05,.001)))
)
glmnet.fit2
## glmnet
##
## 2344 samples
## 15 predictor
##
## No pre-processing
## Resampling: Cross-Validated (5 fold, repeated 1 times)
## Summary of sample sizes: 1875, 1877, 1874, 1875, 1875
## Resampling results across tuning parameters:
##
## lambda RMSE Rsquared MAE
## 0.000 4.438996 0.7821622 3.353113
## 0.001 4.438996 0.7821622 3.353113
## 0.002 4.439178 0.7821469 3.353265
## 0.003 4.439604 0.7821102 3.353665
## 0.004 4.439905 0.7820844 3.354178
## 0.005 4.440391 0.7820411 3.354927
## 0.006 4.441047 0.7819817 3.355913
## 0.007 4.441877 0.7819056 3.356904
## 0.008 4.442881 0.7818127 3.357980
## 0.009 4.444052 0.7817038 3.359160
## 0.010 4.445390 0.7815786 3.360345
## 0.011 4.446942 0.7814329 3.361585
## 0.012 4.448665 0.7812705 3.362960
## 0.013 4.450543 0.7810932 3.364494
## 0.014 4.452643 0.7808933 3.366372
## 0.015 4.454931 0.7806745 3.368319
## 0.016 4.457387 0.7804391 3.370265
## 0.017 4.460005 0.7801876 3.372391
## 0.018 4.462793 0.7799192 3.374614
## 0.019 4.465766 0.7796322 3.376937
## 0.020 4.468895 0.7793297 3.379295
## 0.021 4.472143 0.7790153 3.381720
## 0.022 4.475542 0.7786857 3.384205
## 0.023 4.479080 0.7783420 3.386881
## 0.024 4.482819 0.7779772 3.389618
## 0.025 4.486731 0.7775947 3.392610
## 0.026 4.490825 0.7771933 3.395700
## 0.027 4.495096 0.7767735 3.398865
## 0.028 4.499526 0.7763374 3.402101
## 0.029 4.504118 0.7758847 3.405358
## 0.030 4.508868 0.7754155 3.408641
## 0.031 4.513601 0.7749468 3.411809
## 0.032 4.517809 0.7745270 3.414992
## 0.033 4.522146 0.7740937 3.418897
## 0.034 4.526346 0.7736733 3.422622
## 0.035 4.529756 0.7733298 3.425748
## 0.036 4.533274 0.7729749 3.428874
## 0.037 4.536688 0.7726295 3.431850
## 0.038 4.538484 0.7724495 3.433561
## 0.039 4.539767 0.7723218 3.434705
## 0.040 4.541073 0.7721918 3.435852
## 0.041 4.542062 0.7720926 3.436751
## 0.042 4.542531 0.7720457 3.437187
## 0.043 4.542508 0.7720491 3.437149
## 0.044 4.542487 0.7720524 3.437110
## 0.045 4.542467 0.7720556 3.437071
## 0.046 4.542450 0.7720586 3.437032
## 0.047 4.542435 0.7720615 3.436993
## 0.048 4.542421 0.7720644 3.436953
## 0.049 4.542409 0.7720671 3.436915
## 0.050 4.542399 0.7720696 3.436881
##
## Tuning parameter 'alpha' was held constant at a value of 1
## RMSE was used to select the optimal model using the smallest value.
## The final values used for the model were alpha = 1 and lambda = 0.001.
plot(glmnet.fit2)
opt.pen<-glmnet.fit2$finalModel$lambdaOpt #penalty term
coef(glmnet.fit2$finalModel,opt.pen)
## 17 x 1 sparse Matrix of class "dgCMatrix"
## s1
## (Intercept) 5.044976e+01
## infant.deaths 1.003575e-01
## Alcohol 4.928420e-02
## percentage.expenditure 3.159795e-04
## Measles -3.689026e-06
## BMI 5.226929e-02
## under.five.deaths -7.357662e-02
## poly(Polio, 2)1 5.473565e+01
## poly(Polio, 2)2 5.245271e+01
## Total.expenditure 1.330491e-01
## Diphtheria 2.136060e-02
## HIV.AIDS -6.514221e-01
## log(GDP) 3.653079e-01
## thinness..1.19.years -1.069419e-01
## thinness.5.9.years .
## Income.composition.of.resources 6.837594e+00
## Schooling 7.006484e-01
# Different way to do GLMNET
x=model.matrix(Life.expectancy~infant.deaths + Alcohol +
percentage.expenditure + Measles + BMI +
under.five.deaths + Polio + Total.expenditure +
Diphtheria + HIV.AIDS + log(GDP) +
thinness..1.19.years + thinness.5.9.years +
Income.composition.of.resources + Schooling,
training)[,-1]
y=log(training$Life.expectancy)
library(glmnet)
## Warning: package 'glmnet' was built under R version 4.2.3
## Loading required package: Matrix
##
## Attaching package: 'Matrix'
## The following objects are masked from 'package:tidyr':
##
## expand, pack, unpack
## Loaded glmnet 4.1-7
set.seed(1234)
grid=10^seq(10,-2, length =100)
lasso.mod=glmnet(x,y,alpha=1, lambda =grid)
cv.out=cv.glmnet(x,y,alpha=1)
plot(cv.out)
bestlambda<-cv.out$lambda.1se
coef(cv.out,s=bestlambda)
## 16 x 1 sparse Matrix of class "dgCMatrix"
## s1
## (Intercept) 3.844715e+00
## infant.deaths 3.126175e-04
## Alcohol 1.412272e-04
## percentage.expenditure 2.088892e-06
## Measles -2.066844e-07
## BMI 8.656727e-04
## under.five.deaths -2.420026e-04
## Polio 4.313928e-04
## Total.expenditure 1.324203e-03
## Diphtheria 7.540932e-04
## HIV.AIDS -1.150787e-02
## log(GDP) 6.791475e-03
## thinness..1.19.years -8.147405e-04
## thinness.5.9.years .
## Income.composition.of.resources 1.152774e-01
## Schooling 1.190970e-02
Feature Selection Tools: Forward Selection
fwd.selection = lm(Life.expectancy~infant.deaths + Alcohol +
percentage.expenditure + Measles + BMI +
under.five.deaths + Polio + Total.expenditure +
Diphtheria + HIV.AIDS + log(GDP) +
thinness..1.19.years + thinness.5.9.years +
Income.composition.of.resources + Schooling, data = training)
# Forward
ols_step_forward_p(fwd.selection, penter = 0.05, details = TRUE)
## Forward Selection Method
## ---------------------------
##
## Candidate Terms:
##
## 1. infant.deaths
## 2. Alcohol
## 3. percentage.expenditure
## 4. Measles
## 5. BMI
## 6. under.five.deaths
## 7. Polio
## 8. Total.expenditure
## 9. Diphtheria
## 10. HIV.AIDS
## 11. log(GDP)
## 12. thinness..1.19.years
## 13. thinness.5.9.years
## 14. Income.composition.of.resources
## 15. Schooling
##
## We are selecting variables based on p value...
##
##
## Forward Selection: Step 1
##
## - Schooling
##
## Model Summary
## --------------------------------------------------------------
## R 0.742 RMSE 6.376
## R-Squared 0.550 Coef. Var 9.217
## Adj. R-Squared 0.550 MSE 40.657
## Pred R-Squared 0.548 MAE 4.522
## --------------------------------------------------------------
## RMSE: Root Mean Square Error
## MSE: Mean Square Error
## MAE: Mean Absolute Error
##
## ANOVA
## --------------------------------------------------------------------------
## Sum of
## Squares DF Mean Square F Sig.
## --------------------------------------------------------------------------
## Regression 116351.776 2 58175.888 1430.894 0.0000
## Residual 95178.071 2341 40.657
## Total 211529.848 2343
## --------------------------------------------------------------------------
##
## Parameter Estimates
## ------------------------------------------------------------------------------------------------------------
## model Beta Std. Error Std. Beta t Sig lower upper
## ------------------------------------------------------------------------------------------------------------
## (Intercept) 43.597 0.507 86.019 0.000 42.603 44.591
## Income.composition.of.resources 15.377 1.093 0.329 14.063 0.000 13.233 17.521
## Schooling 1.322 0.069 0.450 19.231 0.000 1.187 1.457
## ------------------------------------------------------------------------------------------------------------
##
##
##
## Forward Selection: Step 2
##
## - HIV.AIDS
##
## Model Summary
## --------------------------------------------------------------
## R 0.838 RMSE 5.191
## R-Squared 0.702 Coef. Var 7.504
## Adj. R-Squared 0.702 MSE 26.948
## Pred R-Squared 0.700 MAE 3.727
## --------------------------------------------------------------
## RMSE: Root Mean Square Error
## MSE: Mean Square Error
## MAE: Mean Absolute Error
##
## ANOVA
## --------------------------------------------------------------------------
## Sum of
## Squares DF Mean Square F Sig.
## --------------------------------------------------------------------------
## Regression 148470.718 3 49490.239 1836.485 0.0000
## Residual 63059.129 2340 26.948
## Total 211529.848 2343
## --------------------------------------------------------------------------
##
## Parameter Estimates
## -------------------------------------------------------------------------------------------------------------
## model Beta Std. Error Std. Beta t Sig lower upper
## -------------------------------------------------------------------------------------------------------------
## (Intercept) 48.062 0.432 111.146 0.000 47.214 48.910
## Income.composition.of.resources 11.453 0.897 0.245 12.762 0.000 9.693 13.213
## Schooling 1.267 0.056 0.431 22.619 0.000 1.157 1.376
## HIV.AIDS -0.750 0.022 -0.402 -34.523 0.000 -0.793 -0.707
## -------------------------------------------------------------------------------------------------------------
##
##
##
## Forward Selection: Step 3
##
## - Diphtheria
##
## Model Summary
## --------------------------------------------------------------
## R 0.855 RMSE 4.931
## R-Squared 0.731 Coef. Var 7.128
## Adj. R-Squared 0.731 MSE 24.314
## Pred R-Squared 0.729 MAE 3.605
## --------------------------------------------------------------
## RMSE: Root Mean Square Error
## MSE: Mean Square Error
## MAE: Mean Absolute Error
##
## ANOVA
## --------------------------------------------------------------------------
## Sum of
## Squares DF Mean Square F Sig.
## --------------------------------------------------------------------------
## Regression 154658.745 4 38664.686 1590.205 0.0000
## Residual 56871.102 2339 24.314
## Total 211529.848 2343
## --------------------------------------------------------------------------
##
## Parameter Estimates
## -------------------------------------------------------------------------------------------------------------
## model Beta Std. Error Std. Beta t Sig lower upper
## -------------------------------------------------------------------------------------------------------------
## (Intercept) 44.282 0.474 93.387 0.000 43.352 45.212
## Income.composition.of.resources 10.312 0.855 0.221 12.055 0.000 8.635 11.989
## Schooling 1.129 0.054 0.385 20.962 0.000 1.024 1.235
## HIV.AIDS -0.722 0.021 -0.387 -34.868 0.000 -0.763 -0.682
## Diphtheria 0.074 0.005 0.186 15.953 0.000 0.065 0.083
## -------------------------------------------------------------------------------------------------------------
##
##
##
## Forward Selection: Step 4
##
## - BMI
##
## Model Summary
## --------------------------------------------------------------
## R 0.865 RMSE 4.776
## R-Squared 0.748 Coef. Var 6.904
## Adj. R-Squared 0.747 MSE 22.813
## Pred R-Squared 0.746 MAE 3.544
## --------------------------------------------------------------
## RMSE: Root Mean Square Error
## MSE: Mean Square Error
## MAE: Mean Absolute Error
##
## ANOVA
## --------------------------------------------------------------------------
## Sum of
## Squares DF Mean Square F Sig.
## --------------------------------------------------------------------------
## Regression 158193.664 5 31638.733 1386.889 0.0000
## Residual 53336.184 2338 22.813
## Total 211529.848 2343
## --------------------------------------------------------------------------
##
## Parameter Estimates
## -------------------------------------------------------------------------------------------------------------
## model Beta Std. Error Std. Beta t Sig lower upper
## -------------------------------------------------------------------------------------------------------------
## (Intercept) 44.336 0.459 96.525 0.000 43.435 45.237
## Income.composition.of.resources 9.331 0.832 0.200 11.211 0.000 7.699 10.963
## Schooling 0.970 0.054 0.330 18.043 0.000 0.864 1.075
## HIV.AIDS -0.690 0.020 -0.370 -34.134 0.000 -0.730 -0.651
## Diphtheria 0.069 0.005 0.174 15.309 0.000 0.060 0.078
## BMI 0.074 0.006 0.154 12.448 0.000 0.062 0.086
## -------------------------------------------------------------------------------------------------------------
##
##
##
## Forward Selection: Step 5
##
## - log(GDP)
##
## Model Summary
## --------------------------------------------------------------
## R 0.869 RMSE 4.704
## R-Squared 0.756 Coef. Var 6.799
## Adj. R-Squared 0.755 MSE 22.125
## Pred R-Squared 0.753 MAE 3.506
## --------------------------------------------------------------
## RMSE: Root Mean Square Error
## MSE: Mean Square Error
## MAE: Mean Absolute Error
##
## ANOVA
## --------------------------------------------------------------------------
## Sum of
## Squares DF Mean Square F Sig.
## --------------------------------------------------------------------------
## Regression 159823.821 6 26637.303 1203.948 0.0000
## Residual 51706.027 2337 22.125
## Total 211529.848 2343
## --------------------------------------------------------------------------
##
## Parameter Estimates
## -------------------------------------------------------------------------------------------------------------
## model Beta Std. Error Std. Beta t Sig lower upper
## -------------------------------------------------------------------------------------------------------------
## (Intercept) 42.099 0.522 80.644 0.000 41.076 43.123
## Income.composition.of.resources 8.057 0.833 0.173 9.672 0.000 6.424 9.691
## Schooling 0.872 0.054 0.297 16.098 0.000 0.765 0.978
## HIV.AIDS -0.686 0.020 -0.368 -34.417 0.000 -0.725 -0.647
## Diphtheria 0.068 0.004 0.171 15.333 0.000 0.060 0.077
## BMI 0.067 0.006 0.140 11.352 0.000 0.055 0.079
## log(GDP) 0.610 0.071 0.111 8.584 0.000 0.471 0.749
## -------------------------------------------------------------------------------------------------------------
##
##
##
## Forward Selection: Step 6
##
## - Polio
##
## Model Summary
## --------------------------------------------------------------
## R 0.871 RMSE 4.679
## R-Squared 0.758 Coef. Var 6.763
## Adj. R-Squared 0.758 MSE 21.889
## Pred R-Squared 0.756 MAE 3.491
## --------------------------------------------------------------
## RMSE: Root Mean Square Error
## MSE: Mean Square Error
## MAE: Mean Absolute Error
##
## ANOVA
## --------------------------------------------------------------------------
## Sum of
## Squares DF Mean Square F Sig.
## --------------------------------------------------------------------------
## Regression 160397.905 7 22913.986 1046.842 0.0000
## Residual 51131.943 2336 21.889
## Total 211529.848 2343
## --------------------------------------------------------------------------
##
## Parameter Estimates
## -------------------------------------------------------------------------------------------------------------
## model Beta Std. Error Std. Beta t Sig lower upper
## -------------------------------------------------------------------------------------------------------------
## (Intercept) 41.581 0.529 78.597 0.000 40.543 42.618
## Income.composition.of.resources 7.914 0.829 0.169 9.546 0.000 6.288 9.540
## Schooling 0.855 0.054 0.291 15.850 0.000 0.749 0.961
## HIV.AIDS -0.683 0.020 -0.367 -34.475 0.000 -0.722 -0.644
## Diphtheria 0.050 0.006 0.125 8.740 0.000 0.039 0.061
## BMI 0.066 0.006 0.137 11.195 0.000 0.054 0.077
## log(GDP) 0.604 0.071 0.110 8.539 0.000 0.465 0.742
## Polio 0.029 0.006 0.073 5.121 0.000 0.018 0.041
## -------------------------------------------------------------------------------------------------------------
##
##
##
## Forward Selection: Step 7
##
## - percentage.expenditure
##
## Model Summary
## --------------------------------------------------------------
## R 0.872 RMSE 4.657
## R-Squared 0.761 Coef. Var 6.732
## Adj. R-Squared 0.760 MSE 21.689
## Pred R-Squared 0.758 MAE 3.479
## --------------------------------------------------------------
## RMSE: Root Mean Square Error
## MSE: Mean Square Error
## MAE: Mean Absolute Error
##
## ANOVA
## -------------------------------------------------------------------------
## Sum of
## Squares DF Mean Square F Sig.
## -------------------------------------------------------------------------
## Regression 160886.865 8 20110.858 927.253 0.0000
## Residual 50642.982 2335 21.689
## Total 211529.848 2343
## -------------------------------------------------------------------------
##
## Parameter Estimates
## -------------------------------------------------------------------------------------------------------------
## model Beta Std. Error Std. Beta t Sig lower upper
## -------------------------------------------------------------------------------------------------------------
## (Intercept) 42.827 0.588 72.787 0.000 41.673 43.980
## Income.composition.of.resources 7.810 0.826 0.167 9.460 0.000 6.191 9.429
## Schooling 0.839 0.054 0.286 15.592 0.000 0.733 0.944
## HIV.AIDS -0.685 0.020 -0.367 -34.709 0.000 -0.724 -0.646
## Diphtheria 0.050 0.006 0.127 8.882 0.000 0.039 0.062
## BMI 0.067 0.006 0.139 11.403 0.000 0.055 0.078
## log(GDP) 0.431 0.079 0.078 5.441 0.000 0.276 0.586
## Polio 0.029 0.006 0.074 5.161 0.000 0.018 0.041
## percentage.expenditure 0.000 0.000 0.059 4.748 0.000 0.000 0.000
## -------------------------------------------------------------------------------------------------------------
##
##
##
## Forward Selection: Step 8
##
## - thinness..1.19.years
##
## Model Summary
## --------------------------------------------------------------
## R 0.873 RMSE 4.640
## R-Squared 0.762 Coef. Var 6.707
## Adj. R-Squared 0.762 MSE 21.527
## Pred R-Squared 0.760 MAE 3.481
## --------------------------------------------------------------
## RMSE: Root Mean Square Error
## MSE: Mean Square Error
## MAE: Mean Absolute Error
##
## ANOVA
## -------------------------------------------------------------------------
## Sum of
## Squares DF Mean Square F Sig.
## -------------------------------------------------------------------------
## Regression 161286.681 9 17920.742 832.492 0.0000
## Residual 50243.166 2334 21.527
## Total 211529.848 2343
## -------------------------------------------------------------------------
##
## Parameter Estimates
## -------------------------------------------------------------------------------------------------------------
## model Beta Std. Error Std. Beta t Sig lower upper
## -------------------------------------------------------------------------------------------------------------
## (Intercept) 44.180 0.665 66.433 0.000 42.876 45.484
## Income.composition.of.resources 7.719 0.823 0.165 9.382 0.000 6.105 9.332
## Schooling 0.814 0.054 0.277 15.106 0.000 0.709 0.920
## HIV.AIDS -0.680 0.020 -0.364 -34.497 0.000 -0.718 -0.641
## Diphtheria 0.050 0.006 0.125 8.769 0.000 0.039 0.061
## BMI 0.057 0.006 0.118 8.989 0.000 0.044 0.069
## log(GDP) 0.433 0.079 0.079 5.483 0.000 0.278 0.588
## Polio 0.029 0.006 0.074 5.188 0.000 0.018 0.041
## percentage.expenditure 0.000 0.000 0.055 4.437 0.000 0.000 0.000
## thinness..1.19.years -0.115 0.027 -0.053 -4.310 0.000 -0.168 -0.063
## -------------------------------------------------------------------------------------------------------------
##
##
##
## Forward Selection: Step 9
##
## - Total.expenditure
##
## Model Summary
## --------------------------------------------------------------
## R 0.874 RMSE 4.629
## R-Squared 0.764 Coef. Var 6.691
## Adj. R-Squared 0.763 MSE 21.428
## Pred R-Squared 0.761 MAE 3.474
## --------------------------------------------------------------
## RMSE: Root Mean Square Error
## MSE: Mean Square Error
## MAE: Mean Absolute Error
##
## ANOVA
## -------------------------------------------------------------------------
## Sum of
## Squares DF Mean Square F Sig.
## -------------------------------------------------------------------------
## Regression 161538.357 10 16153.836 753.866 0.0000
## Residual 49991.490 2333 21.428
## Total 211529.848 2343
## -------------------------------------------------------------------------
##
## Parameter Estimates
## -------------------------------------------------------------------------------------------------------------
## model Beta Std. Error Std. Beta t Sig lower upper
## -------------------------------------------------------------------------------------------------------------
## (Intercept) 43.422 0.699 62.084 0.000 42.051 44.794
## Income.composition.of.resources 7.910 0.823 0.169 9.615 0.000 6.297 9.524
## Schooling 0.795 0.054 0.271 14.704 0.000 0.689 0.901
## HIV.AIDS -0.685 0.020 -0.367 -34.741 0.000 -0.724 -0.646
## Diphtheria 0.049 0.006 0.122 8.580 0.000 0.037 0.060
## BMI 0.054 0.006 0.113 8.631 0.000 0.042 0.067
## log(GDP) 0.454 0.079 0.083 5.751 0.000 0.299 0.609
## Polio 0.029 0.006 0.073 5.177 0.000 0.018 0.040
## percentage.expenditure 0.000 0.000 0.051 4.029 0.000 0.000 0.000
## thinness..1.19.years -0.102 0.027 -0.047 -3.795 0.000 -0.155 -0.049
## Total.expenditure 0.145 0.042 0.037 3.427 0.001 0.062 0.228
## -------------------------------------------------------------------------------------------------------------
##
##
##
## No more variables to be added.
##
## Variables Entered:
##
## + Income.composition.of.resources
## + Schooling
## + HIV.AIDS
## + Diphtheria
## + BMI
## + log(GDP)
## + Polio
## + percentage.expenditure
## + thinness..1.19.years
## + Total.expenditure
##
##
## Final Model Output
## ------------------
##
## Model Summary
## --------------------------------------------------------------
## R 0.874 RMSE 4.629
## R-Squared 0.764 Coef. Var 6.691
## Adj. R-Squared 0.763 MSE 21.428
## Pred R-Squared 0.761 MAE 3.474
## --------------------------------------------------------------
## RMSE: Root Mean Square Error
## MSE: Mean Square Error
## MAE: Mean Absolute Error
##
## ANOVA
## -------------------------------------------------------------------------
## Sum of
## Squares DF Mean Square F Sig.
## -------------------------------------------------------------------------
## Regression 161538.357 10 16153.836 753.866 0.0000
## Residual 49991.490 2333 21.428
## Total 211529.848 2343
## -------------------------------------------------------------------------
##
## Parameter Estimates
## -------------------------------------------------------------------------------------------------------------
## model Beta Std. Error Std. Beta t Sig lower upper
## -------------------------------------------------------------------------------------------------------------
## (Intercept) 43.422 0.699 62.084 0.000 42.051 44.794
## Income.composition.of.resources 7.910 0.823 0.169 9.615 0.000 6.297 9.524
## Schooling 0.795 0.054 0.271 14.704 0.000 0.689 0.901
## HIV.AIDS -0.685 0.020 -0.367 -34.741 0.000 -0.724 -0.646
## Diphtheria 0.049 0.006 0.122 8.580 0.000 0.037 0.060
## BMI 0.054 0.006 0.113 8.631 0.000 0.042 0.067
## log(GDP) 0.454 0.079 0.083 5.751 0.000 0.299 0.609
## Polio 0.029 0.006 0.073 5.177 0.000 0.018 0.040
## percentage.expenditure 0.000 0.000 0.051 4.029 0.000 0.000 0.000
## thinness..1.19.years -0.102 0.027 -0.047 -3.795 0.000 -0.155 -0.049
## Total.expenditure 0.145 0.042 0.037 3.427 0.001 0.062 0.228
## -------------------------------------------------------------------------------------------------------------
##
## Selection Summary
## ----------------------------------------------------------------------------------------------------
## Variable Adj.
## Step Entered R-Square R-Square C(p) AIC RMSE
## ----------------------------------------------------------------------------------------------------
## 1 Income.composition.of.resources 0.5500 0.5497 2327.9505 15341.9036 6.3763
## 2 Schooling 0.7019 0.7015 755.3715 14378.9334 5.1912
## 3 HIV.AIDS 0.7311 0.7307 454.0135 14138.8322 4.9310
## 4 Diphtheria 0.7479 0.7473 282.7199 13990.4121 4.7763
## 5 BMI 0.7556 0.7549 204.8041 13919.6529 4.7037
## 6 log(GDP) 0.7583 0.7576 178.6605 13895.4823 4.6785
## 7 Polio 0.7606 0.7598 156.6900 13874.9594 4.6571
## 8 percentage.expenditure 0.7625 0.7616 139.0897 13858.3806 4.6397
## 9 thinness..1.19.years 0.7637 0.7627 128.7517 13848.6096 4.6290
## 10 Total.expenditure NA NA NA NA NA
## ----------------------------------------------------------------------------------------------------
# Forward Selection Chosen Model
fwd.select.model <- lm(Life.expectancy~ Income.composition.of.resources + Schooling +
HIV.AIDS + Diphtheria +
BMI + log(GDP) + Polio +
percentage.expenditure + thinness..1.19.years + Total.expenditure, training)
plot(fwd.select.model)
library(leaps)
## Warning: package 'leaps' was built under R version 4.2.3
reg.fwd=regsubsets(Life.expectancy~infant.deaths + Alcohol +
percentage.expenditure + Measles + BMI +
under.five.deaths + Polio + Total.expenditure +
Diphtheria + HIV.AIDS + log(GDP) +
thinness..1.19.years + thinness.5.9.years +
Income.composition.of.resources + Schooling,
data=training,method="forward",nvmax=15)
summary(reg.fwd)$adjr2
## [1] 0.5118279 0.6808674 0.7140742 0.7338469 0.7473158 0.7549340 0.7575512
## [8] 0.7597668 0.7615613 0.7626540 0.7628746 0.7628610 0.7737752 0.7741531
## [15] 0.7740578
summary(reg.fwd)$rss
## [1] 103218.90 67448.44 60404.40 56203.20 53336.18 51706.03 51131.94
## [8] 50642.98 50243.17 49991.49 49923.61 49905.07 47587.78 47487.89
## [15] 47487.55
summary(reg.fwd)$bic
## [1] -1666.334 -2655.919 -2906.706 -3067.922 -3182.891 -3247.891 -3266.302
## [8] -3281.065 -3291.884 -3295.895 -3291.321 -3284.432 -3388.122 -3385.287
## [15] -3377.544
par(mfrow=c(1,3))
bics<-summary(reg.fwd)$bic
plot(1:15,bics,type="l",ylab="BIC",xlab="# of predictors")
index<-which(bics==min(bics))
points(index,bics[index],col="red",pch=10)
adjr2<-summary(reg.fwd)$adjr2
plot(1:15,adjr2,type="l",ylab="Adjusted R-squared",xlab="# of predictors")
index<-which(adjr2==max(adjr2))
points(index,adjr2[index],col="red",pch=10)
rss<-summary(reg.fwd)$rss
plot(1:15,rss,type="l",ylab="train RSS",xlab="# of predictors")
index<-which(rss==min(rss))
points(index,rss[index],col="red",pch=10)
Backward Selection
bck.selection = lm(Life.expectancy~infant.deaths + Alcohol +
percentage.expenditure + Measles + BMI +
under.five.deaths + Polio + Total.expenditure +
Diphtheria + HIV.AIDS + log(GDP) +
thinness..1.19.years + thinness.5.9.years +
Income.composition.of.resources + Schooling, data = training)
# Backward
ols_step_backward_p(bck.selection, prem = 0.05, details = TRUE)
## Backward Elimination Method
## ---------------------------
##
## Candidate Terms:
##
## 1 . infant.deaths
## 2 . Alcohol
## 3 . percentage.expenditure
## 4 . Measles
## 5 . BMI
## 6 . under.five.deaths
## 7 . Polio
## 8 . Total.expenditure
## 9 . Diphtheria
## 10 . HIV.AIDS
## 11 . log(GDP)
## 12 . thinness..1.19.years
## 13 . thinness.5.9.years
## 14 . Income.composition.of.resources
## 15 . Schooling
##
## We are eliminating variables based on p value...
##
## - thinness.5.9.years
##
## Backward Elimination: Step 1
##
## Variable thinness.5.9.years Removed
##
## Model Summary
## --------------------------------------------------------------
## R 0.881 RMSE 4.516
## R-Squared 0.776 Coef. Var 6.527
## Adj. R-Squared 0.774 MSE 20.390
## Pred R-Squared 0.771 MAE 3.389
## --------------------------------------------------------------
## RMSE: Root Mean Square Error
## MSE: Mean Square Error
## MAE: Mean Absolute Error
##
## ANOVA
## -------------------------------------------------------------------------
## Sum of
## Squares DF Mean Square F Sig.
## -------------------------------------------------------------------------
## Regression 164041.953 14 11717.282 574.663 0.0000
## Residual 47487.895 2329 20.390
## Total 211529.848 2343
## -------------------------------------------------------------------------
##
## Parameter Estimates
## -------------------------------------------------------------------------------------------------------------
## model Beta Std. Error Std. Beta t Sig lower upper
## -------------------------------------------------------------------------------------------------------------
## (Intercept) 45.159 0.702 64.284 0.000 43.781 46.536
## infant.deaths 0.112 0.010 1.387 10.864 0.000 0.091 0.132
## Alcohol 0.067 0.030 0.027 2.213 0.027 0.008 0.127
## percentage.expenditure 0.000 0.000 0.055 4.452 0.000 0.000 0.000
## Measles 0.000 0.000 -0.005 -0.419 0.675 0.000 0.000
## BMI 0.053 0.006 0.111 8.655 0.000 0.041 0.065
## under.five.deaths -0.083 0.008 -1.404 -10.912 0.000 -0.098 -0.068
## Polio 0.026 0.006 0.065 4.670 0.000 0.015 0.037
## Total.expenditure 0.132 0.042 0.034 3.160 0.002 0.050 0.215
## Diphtheria 0.041 0.006 0.103 7.341 0.000 0.030 0.052
## HIV.AIDS -0.671 0.019 -0.360 -34.460 0.000 -0.710 -0.633
## log(GDP) 0.443 0.077 0.081 5.723 0.000 0.291 0.594
## thinness..1.19.years -0.096 0.030 -0.044 -3.233 0.001 -0.154 -0.038
## Income.composition.of.resources 7.023 0.809 0.150 8.681 0.000 5.436 8.609
## Schooling 0.768 0.054 0.262 14.235 0.000 0.662 0.874
## -------------------------------------------------------------------------------------------------------------
##
##
## - Measles
##
## Backward Elimination: Step 2
##
## Variable Measles Removed
##
## Model Summary
## --------------------------------------------------------------
## R 0.881 RMSE 4.515
## R-Squared 0.775 Coef. Var 6.526
## Adj. R-Squared 0.774 MSE 20.383
## Pred R-Squared 0.772 MAE 3.389
## --------------------------------------------------------------
## RMSE: Root Mean Square Error
## MSE: Mean Square Error
## MAE: Mean Absolute Error
##
## ANOVA
## -------------------------------------------------------------------------
## Sum of
## Squares DF Mean Square F Sig.
## -------------------------------------------------------------------------
## Regression 164038.369 13 12618.336 619.074 0.0000
## Residual 47491.479 2330 20.383
## Total 211529.848 2343
## -------------------------------------------------------------------------
##
## Parameter Estimates
## -------------------------------------------------------------------------------------------------------------
## model Beta Std. Error Std. Beta t Sig lower upper
## -------------------------------------------------------------------------------------------------------------
## (Intercept) 45.142 0.701 64.370 0.000 43.767 46.518
## infant.deaths 0.112 0.010 1.391 10.919 0.000 0.092 0.132
## Alcohol 0.067 0.030 0.027 2.208 0.027 0.007 0.127
## percentage.expenditure 0.000 0.000 0.055 4.459 0.000 0.000 0.000
## BMI 0.054 0.006 0.112 8.710 0.000 0.042 0.066
## under.five.deaths -0.083 0.008 -1.411 -11.035 0.000 -0.098 -0.068
## Polio 0.026 0.006 0.065 4.667 0.000 0.015 0.037
## Total.expenditure 0.133 0.042 0.034 3.185 0.001 0.051 0.215
## Diphtheria 0.041 0.006 0.103 7.348 0.000 0.030 0.052
## HIV.AIDS -0.671 0.019 -0.360 -34.464 0.000 -0.709 -0.633
## log(GDP) 0.442 0.077 0.080 5.719 0.000 0.290 0.594
## thinness..1.19.years -0.095 0.030 -0.044 -3.212 0.001 -0.153 -0.037
## Income.composition.of.resources 7.035 0.808 0.151 8.704 0.000 5.450 8.620
## Schooling 0.767 0.054 0.261 14.231 0.000 0.662 0.873
## -------------------------------------------------------------------------------------------------------------
##
##
##
## No more variables satisfy the condition of p value = 0.05
##
##
## Variables Removed:
##
## - thinness.5.9.years
## - Measles
##
##
## Final Model Output
## ------------------
##
## Model Summary
## --------------------------------------------------------------
## R 0.881 RMSE 4.515
## R-Squared 0.775 Coef. Var 6.526
## Adj. R-Squared 0.774 MSE 20.383
## Pred R-Squared 0.772 MAE 3.389
## --------------------------------------------------------------
## RMSE: Root Mean Square Error
## MSE: Mean Square Error
## MAE: Mean Absolute Error
##
## ANOVA
## -------------------------------------------------------------------------
## Sum of
## Squares DF Mean Square F Sig.
## -------------------------------------------------------------------------
## Regression 164038.369 13 12618.336 619.074 0.0000
## Residual 47491.479 2330 20.383
## Total 211529.848 2343
## -------------------------------------------------------------------------
##
## Parameter Estimates
## -------------------------------------------------------------------------------------------------------------
## model Beta Std. Error Std. Beta t Sig lower upper
## -------------------------------------------------------------------------------------------------------------
## (Intercept) 45.142 0.701 64.370 0.000 43.767 46.518
## infant.deaths 0.112 0.010 1.391 10.919 0.000 0.092 0.132
## Alcohol 0.067 0.030 0.027 2.208 0.027 0.007 0.127
## percentage.expenditure 0.000 0.000 0.055 4.459 0.000 0.000 0.000
## BMI 0.054 0.006 0.112 8.710 0.000 0.042 0.066
## under.five.deaths -0.083 0.008 -1.411 -11.035 0.000 -0.098 -0.068
## Polio 0.026 0.006 0.065 4.667 0.000 0.015 0.037
## Total.expenditure 0.133 0.042 0.034 3.185 0.001 0.051 0.215
## Diphtheria 0.041 0.006 0.103 7.348 0.000 0.030 0.052
## HIV.AIDS -0.671 0.019 -0.360 -34.464 0.000 -0.709 -0.633
## log(GDP) 0.442 0.077 0.080 5.719 0.000 0.290 0.594
## thinness..1.19.years -0.095 0.030 -0.044 -3.212 0.001 -0.153 -0.037
## Income.composition.of.resources 7.035 0.808 0.151 8.704 0.000 5.450 8.620
## Schooling 0.767 0.054 0.261 14.231 0.000 0.662 0.873
## -------------------------------------------------------------------------------------------------------------
##
##
## Elimination Summary
## -------------------------------------------------------------------------------------
## Variable Adj.
## Step Removed R-Square R-Square C(p) AIC RMSE
## -------------------------------------------------------------------------------------
## 1 thinness.5.9.years 0.7755 0.7742 14.0170 13736.1797 4.5155
## 2 Measles 0.7755 0.7742 12.1927 13734.3566 4.5147
## -------------------------------------------------------------------------------------
# Backward Selection Chosen Model
bck.select.model <- lm(Life.expectancy~infant.deaths + Alcohol +
percentage.expenditure + BMI +
under.five.deaths + Polio + Total.expenditure +
Diphtheria + HIV.AIDS + log(GDP) +
thinness..1.19.years +
Income.composition.of.resources + Schooling, data = training)
plot(bck.select.model)
Stepwise Selection
sw.selection = lm(Life.expectancy~infant.deaths + Alcohol +
percentage.expenditure + Measles + BMI +
under.five.deaths + Polio + Total.expenditure +
Diphtheria + HIV.AIDS + log(GDP) +
thinness..1.19.years + thinness.5.9.years +
Income.composition.of.resources + Schooling, data = training)
summary(sw.selection)
##
## Call:
## lm(formula = Life.expectancy ~ infant.deaths + Alcohol + percentage.expenditure +
## Measles + BMI + under.five.deaths + Polio + Total.expenditure +
## Diphtheria + HIV.AIDS + log(GDP) + thinness..1.19.years +
## thinness.5.9.years + Income.composition.of.resources + Schooling,
## data = training)
##
## Residuals:
## Min 1Q Median 3Q Max
## -26.0853 -2.5875 0.0947 2.6344 18.6763
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.515e+01 7.078e-01 63.787 < 2e-16 ***
## infant.deaths 1.115e-01 1.028e-02 10.853 < 2e-16 ***
## Alcohol 6.734e-02 3.040e-02 2.215 0.02686 *
## percentage.expenditure 2.696e-04 6.057e-05 4.451 8.96e-06 ***
## Measles -3.885e-06 9.417e-06 -0.413 0.67999
## BMI 5.349e-02 6.217e-03 8.604 < 2e-16 ***
## under.five.deaths -8.275e-02 7.588e-03 -10.906 < 2e-16 ***
## Polio 2.584e-02 5.535e-03 4.669 3.20e-06 ***
## Total.expenditure 1.327e-01 4.197e-02 3.161 0.00159 **
## Diphtheria 4.087e-02 5.571e-03 7.336 3.03e-13 ***
## HIV.AIDS -6.714e-01 1.951e-02 -34.419 < 2e-16 ***
## log(GDP) 4.431e-01 7.745e-02 5.721 1.20e-08 ***
## thinness..1.19.years -1.031e-01 6.194e-02 -1.665 0.09611 .
## thinness.5.9.years 7.969e-03 6.110e-02 0.130 0.89624
## Income.composition.of.resources 7.023e+00 8.091e-01 8.679 < 2e-16 ***
## Schooling 7.680e-01 5.398e-02 14.226 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.516 on 2328 degrees of freedom
## Multiple R-squared: 0.7755, Adjusted R-squared: 0.7741
## F-statistic: 536.1 on 15 and 2328 DF, p-value: < 2.2e-16
# Stepwise
ols_step_both_p(sw.selection, prem = 0.05, pent = 0.05, details = FALSE)
##
## Stepwise Selection Summary
## ----------------------------------------------------------------------------------------------------------------
## Added/ Adj.
## Step Variable Removed R-Square R-Square C(p) AIC RMSE
## ----------------------------------------------------------------------------------------------------------------
## 1 Income.composition.of.resources addition 0.550 0.550 2327.9510 15341.9036 6.3763
## 2 Schooling addition 0.702 0.702 755.3720 14378.9334 5.1912
## 3 HIV.AIDS addition 0.731 0.731 454.0140 14138.8322 4.9310
## 4 Diphtheria addition 0.748 0.747 282.7200 13990.4121 4.7763
## 5 BMI addition 0.756 0.755 204.8040 13919.6529 4.7037
## 6 log(GDP) addition 0.758 0.758 178.6610 13895.4823 4.6785
## 7 Polio addition 0.761 0.760 156.6900 13874.9594 4.6571
## 8 percentage.expenditure addition 0.762 0.762 139.0900 13858.3806 4.6397
## 9 thinness..1.19.years addition 0.764 0.763 128.7520 13848.6096 4.6290
## ----------------------------------------------------------------------------------------------------------------
# Stepwise Selection Chosen Model
sw.select.model = lm(Life.expectancy~ percentage.expenditure +
BMI + Polio + Diphtheria + HIV.AIDS +
log(GDP) + thinness..1.19.years +
Income.composition.of.resources + Schooling, data = training)
plot(sw.select.model)
Forward Selection Validation
fwd.train=regsubsets(Life.expectancy~infant.deaths + Alcohol +
percentage.expenditure + Measles + BMI +
under.five.deaths + Polio + Total.expenditure +
Diphtheria + HIV.AIDS + log(GDP) +
thinness..1.19.years + thinness.5.9.years +
Income.composition.of.resources + Schooling,
data=training,method="forward",nvmax=15)
#Creating a prediction function
predict.regsubsets =function (object , newdata ,id ,...){
form=as.formula (object$call [[2]])
mat=model.matrix(form ,newdata )
coefi=coef(object ,id=id)
xvars=names(coefi)
mat[,xvars]%*%coefi
}
valMSE<-c()
#note my index, i, is to 15 since that is how many predictors I went up to during fwd selection
for (i in 1:15){
predictions<-predict.regsubsets(object=fwd.train,newdata=validate,id=i)
valMSE[i]<-mean((validate$Life.expectancy-predictions)^2)
}
par(mfrow=c(1,1))
plot(1:15,sqrt(valMSE),type="l",xlab="# of predictors",
ylab="test vs train RMSE")
index<-which(valMSE==min(valMSE))
points(index,sqrt(valMSE[index]),col="red",pch=10)
trainMSE<-summary(fwd.train)$rss/nrow(training)
lines(1:15,sqrt(trainMSE),lty=3,col="blue")
Adding Complexity to the Model
# Transformations using Polio as a test
transformations <- training
# Transforming with Polynomial using a ^2
transformations$polio2 <- transformations$Polio^2
transformations %>% ggplot(aes(x=polio2, y=Life.expectancy)) +
geom_point() + geom_smooth()
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
# Transforming using Log
transformations$logPolio <- log(transformations$Polio)
transformations %>% ggplot(aes(x=logPolio, y=Life.expectancy)) +
geom_point() + geom_smooth()
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
# Testing if it's the same as logging inside the plot
transformations %>% ggplot(aes(x=log(Polio), y=Life.expectancy)) +
geom_point() + geom_smooth()
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
Creating plot functions
# Original Data plot
plot_original <- function(var1) {
return(training %>% ggplot(aes(x=var1,
y = Life.expectancy,
color=Status)) +
geom_point() + geom_smooth () + ylab("Life Expectancy in Age")
)
}
plot_original(training$Polio)+
xlab("Polio Immunization Coverage among 1-year-olds")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
# Creating function to plot variable as polynomials
plot_poly <- function(var1) {
return(training %>% ggplot(aes(x=var1^2,
y = Life.expectancy,
color=Status)) +
geom_point() + geom_smooth () + ylab("Life Expectancy in Age")
)
}
plot_poly(training$Polio)+
xlab("Polio Immunization Coverage among 1-year-olds")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
# Creating function to plot variables as logged
plot_log <- function(var1) {
return(training %>% ggplot(aes(x=log(var1),
y = Life.expectancy,
color=Status)) +
geom_point() + geom_smooth () + ylab("Life Expectancy in Age")
)
}
plot_log(training$Polio) +
xlab("Polio Immunization Coverage among 1-year-olds")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
Putting each Variable into the Function
# Infant Deaths Variable
plot_original(training$infant.deaths) + xlab("Infant Deaths per 1000")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
plot_poly(training$infant.deaths) + xlab("Infant Deaths per 1000")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
plot_log(training$infant.deaths) + xlab("Infant Deaths per 1000")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 656 rows containing non-finite values (`stat_smooth()`).
# Alcohol Variable
plot_original(training$Alcohol) +
xlab("Alcohol Consumption per capita in Litres of pure alcohol")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
plot_poly(training$Alcohol) +
xlab("Alcohol Consumption per capita in Litres of pure alcohol")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
plot_log(training$Alcohol) +
xlab("Alcohol Consumption per capita in Litres of pure alcohol")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
# Percentage of Expenditures Variable
plot_original(training$percentage.expenditure) +
xlab("Expenditure on health as a percentage of Gross Domestic Product per capita")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
plot_poly(training$percentage.expenditure) +
xlab("Expenditure on health as a percentage of Gross Domestic Product per capita")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
plot_log(training$percentage.expenditure) +
xlab("Expenditure on health as a percentage of Gross Domestic Product per capita")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 500 rows containing non-finite values (`stat_smooth()`).
# Measles Variable
plot_original(training$Measles) + xlab("Reported Measles cases per 1000")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
plot_poly(training$Measles)+ xlab("Reported Measles cases per 1000")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
plot_log(training$Measles)+ xlab("Reported Measles cases per 1000")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 778 rows containing non-finite values (`stat_smooth()`).
# BMI Variable
plot_original(training$BMI) + xlab("Average Body Mass Index of population")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
plot_poly(training$BMI)+ xlab("Average Body Mass Index of population")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
plot_log(training$BMI)+ xlab("Average Body Mass Index of population")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
# Under Five Deaths Variable
plot_original(training$under.five.deaths) +
xlab("Under age 5 deaths per 1000")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
plot_poly(training$under.five.deaths)+
xlab("Under age 5 deaths per 1000")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
plot_log(training$under.five.deaths)+
xlab("Under age 5 deaths per 1000")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 604 rows containing non-finite values (`stat_smooth()`).
# Total Expenditures Variable
plot_original(training$Total.expenditure) +
xlab("Percentage of total government expenditures on health")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
plot_poly(training$Total.expenditure)+
xlab("Percentage of total government expenditures on health")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
plot_log(training$Total.expenditure)+
xlab("Percentage of total government expenditures on health")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
# Diphtheria Variable
plot_original(training$Diphtheria) +
xlab("DPT3 Immunization Coverage among 1-year-olds")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
plot_poly(training$Diphtheria)+
xlab("DPT3 Immunization Coverage among 1-year-olds")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
plot_log(training$Diphtheria)+
xlab("DPT3 Immunization Coverage among 1-year-olds")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
# HIV AIDS Variable
plot_original(training$HIV.AIDS) + xlab ("HIV/AIDS Deaths per 1000 live births")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
plot_poly(training$HIV.AIDS)+ xlab ("HIV/AIDS Deaths per 1000 live births")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
plot_log(training$HIV.AIDS)+ xlab ("HIV/AIDS Deaths per 1000 live births")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
# GDP Variable
plot_original(training$GDP) + xlab("Gross Domestic Product per capita in USD")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
plot_poly(training$GDP)+ xlab("Gross Domestic Product per capita in USD")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
plot_log(training$GDP)+ xlab("Gross Domestic Product per capita in USD")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
# Thinness 10-19 Years Variable
plot_original(training$thinness..1.19.years) +
xlab("Prevalence of thinness among children ages 10 to 19")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
plot_poly(training$thinness..1.19.years)+
xlab("Prevalence of thinness among children ages 10 to 19")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
plot_log(training$thinness..1.19.years)+
xlab("Prevalence of thinness among children ages 10 to 19")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
# Thinness 5-9 Variable
plot_original(training$thinness.5.9.years)+
xlab("Prevalence of thinness among children ages 5 to 9")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
plot_poly(training$thinness.5.9.years)+
xlab("Prevalence of thinness among children ages 5 to 9")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
plot_log(training$thinness.5.9.years)+
xlab("Prevalence of thinness among children ages 5 to 9")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
# Income Composition of Resources Variable
plot_original(training$Income.composition.of.resources) +
xlab("Human Development Index in terms of income composition of resources")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
plot_poly(training$Income.composition.of.resources)+
xlab("Human Development Index in terms of income composition of resources")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
plot_log(training$Income.composition.of.resources)+
xlab("Human Development Index in terms of income composition of resources")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 101 rows containing non-finite values (`stat_smooth()`).
# Schooling Variable
plot_original(training$Schooling) + xlab("Years in School")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
plot_poly(training$Schooling)+ xlab("Years in School")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
plot_log(training$Schooling)+ xlab("Years in School")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 21 rows containing non-finite values (`stat_smooth()`).
Original Model for comparison
original.model <- lm(Life.expectancy~ Polio + Alcohol + BMI +
Diphtheria+Schooling + HIV.AIDS + GDP +
thinness..1.19.years + Measles + Total.expenditure +
Income.composition.of.resources, training)
plot(original.model)
Fitting a complex model with polynomials up to 2 & logged
variables
poly2logmodel <- lm(Life.expectancy~ poly(Polio,2)+
poly(Alcohol,2)+
poly(BMI,2)+
poly(Diphtheria,2)+
poly(Schooling,2)+
log(HIV.AIDS) +
log(GDP) +
log(thinness..1.19.years) +
Measles +
Total.expenditure+
Income.composition.of.resources, training)
plot(poly2logmodel)
Fitting a complex model with polynomials up to 7 & logged variables
poly7logmodel <- lm(Life.expectancy~ poly(Polio,7)+
sqrt(Alcohol)+
poly(BMI,7)+
poly(Diphtheria,5)+
poly(Schooling,7)+
log(HIV.AIDS) +
log(GDP) +
log(thinness..1.19.years) +
Measles +
Total.expenditure+
Income.composition.of.resources, training)
plot(poly7logmodel)
Fitting interaction terms on regular model
interaction.model <- lm(Life.expectancy~ Polio:Status+Alcohol:Status+BMI:Status+
Diphtheria:Status+Schooling:Status+
HIV.AIDS:Status+GDP:Status+
thinness..1.19.years:Status+
Measles:Status+Total.expenditure:Status+
Income.composition.of.resources:Status, training)
plot(interaction.model)
Fitting interaction on poly2logmodel
poly2log.interaction.model <- lm(Life.expectancy~ poly(Polio,2):Status+
poly(Alcohol,2):Status+
poly(BMI,2):Status+
poly(Diphtheria,2):Status+
poly(Schooling,2):Status+
log(HIV.AIDS):Status +
log(GDP):Status +
log(thinness..1.19.years):Status +
Measles:Status +
Total.expenditure:Status+
Income.composition.of.resources:Status, training)
plot(poly2log.interaction.model)
Fitting interaction on poly7logmodel
poly7log.interaction.model <- lm(Life.expectancy~ poly(Polio,7):Status+
sqrt(Alcohol):Status+
poly(BMI,7):Status+
poly(Diphtheria,5):Status+
poly(Schooling,7):Status+
log(HIV.AIDS):Status +
log(GDP):Status +
log(thinness..1.19.years):Status +
Measles:Status +
Total.expenditure:Status+
Income.composition.of.resources:Status, training)
plot(poly7log.interaction.model)
## Warning in sqrt(crit * p * (1 - hh)/hh): NaNs produced
## Warning in sqrt(crit * p * (1 - hh)/hh): NaNs produced
Fitting a complex model with polynomials up to 7 & logged variables and categorical variable Status
status.poly7logmodel <- lm(Life.expectancy~ Status + poly(Polio,7)+
sqrt(Alcohol)+
poly(BMI,7)+
poly(Diphtheria,5)+
poly(Schooling,7)+
log(HIV.AIDS) +
log(GDP) +
log(thinness..1.19.years) +
Measles +
Total.expenditure+
Income.composition.of.resources, training)
plot(status.poly7logmodel)
Simple Model
simple <- lm(Life.expectancy ~ HIV.AIDS + Alcohol:Status + Total.expenditure, training)
plot(simple)
Predictions
# RMSE of Full Model
full.model_Preds = predict(full.model, newdata = validate)
as.data.frame(full.model_Preds)
## full.model_Preds
## 1 61.26067
## 6 61.25329
## 7 60.65273
## 9 59.60362
## 10 58.92236
## 24 74.83362
## 28 74.02891
## 33 77.00425
## 35 75.13027
## 36 74.97686
## 42 72.21996
## 43 69.57465
## 48 69.55915
## 49 60.78034
## 57 57.42985
## 59 54.85236
## 60 50.96067
## 79 60.45561
## 80 60.34527
## 82 78.07716
## 105 69.87373
## 108 70.83053
## 115 85.80442
## 124 80.72788
## 129 80.11401
## 130 82.30248
## 136 79.67392
## 137 81.06677
## 151 70.70706
## 156 68.57278
## 157 69.05886
## 159 67.54161
## 164 73.31474
## 168 70.69792
## 174 75.33841
## 176 67.67137
## 182 73.59226
## 184 75.54608
## 186 75.27304
## 190 74.33864
## 193 67.93994
## 194 67.47006
## 201 64.58460
## 204 64.47756
## 206 63.11098
## 209 76.49412
## 210 78.66034
## 213 78.07706
## 218 74.81362
## 221 71.44372
## 223 73.59979
## 226 75.47800
## 232 74.12091
## 240 71.08439
## 242 81.74112
## 247 79.16743
## 258 70.34347
## 259 75.49176
## 264 70.95470
## 278 62.60389
## 285 59.68380
## 287 58.81592
## 288 58.80564
## 289 68.65665
## 296 63.03336
## 297 62.52069
## 298 61.92907
## 306 72.37380
## 307 71.99719
## 312 70.89394
## 318 69.60384
## 338 68.43750
## 339 65.99361
## 345 59.13624
## 351 41.36218
## 356 75.59812
## 368 74.39652
## 371 76.57313
## 375 75.42010
## 386 77.31309
## 402 60.53706
## 406 57.70129
## 409 57.33817
## 415 49.38363
## 418 63.46357
## 419 68.67638
## 426 56.78735
## 429 53.38613
## 430 52.96413
## 446 56.03499
## 448 58.46316
## 450 70.89334
## 451 74.03501
## 452 70.58919
## 453 65.60153
## 459 68.35909
## 460 71.43905
## 465 68.02868
## 468 65.67622
## 478 59.25434
## 480 56.73935
## 482 61.07593
## 492 54.28354
## 493 54.94886
## 503 78.47312
## 505 78.21713
## 509 76.75123
## 511 80.01854
## 513 54.66215
## 516 53.25230
## 518 51.22319
## 523 47.94482
## 527 53.17321
## 532 53.03313
## 537 50.44184
## 545 78.26372
## 555 76.23276
## 556 74.89891
## 559 76.87118
## 577 72.87396
## 580 73.72002
## 596 65.41644
## 601 62.04037
## 603 62.59913
## 614 62.23064
## 626 72.59401
## 627 74.94629
## 635 75.49435
## 642 78.56416
## 645 80.55068
## 646 80.48588
## 655 74.93939
## 658 74.89361
## 665 78.79516
## 673 72.64484
## 686 77.29558
## 698 77.40339
## 699 77.28158
## 701 72.96864
## 720 68.87919
## 729 64.11346
## 732 55.50850
## 751 82.77830
## 752 81.00838
## 758 60.54792
## 760 60.52456
## 767 55.46539
## 771 72.82218
## 774 72.08523
## 788 74.19228
## 798 69.16284
## 807 72.38294
## 816 70.71415
## 822 72.14057
## 823 69.55891
## 825 74.82460
## 835 63.61844
## 840 59.18490
## 847 59.03783
## 853 60.94309
## 858 58.84906
## 859 58.46482
## 864 51.12897
## 872 77.30293
## 876 75.83902
## 878 74.18127
## 881 72.85571
## 884 61.64156
## 894 47.99681
## 898 43.03886
## 899 74.33955
## 902 71.20336
## 904 77.07567
## 906 76.29953
## 911 75.04965
## 922 78.79857
## 925 81.58379
## 926 82.29014
## 931 78.97052
## 934 78.89706
## 935 76.28322
## 954 62.09361
## 958 58.40540
## 960 58.72495
## 961 65.45976
## 971 61.96682
## 978 62.89673
## 979 74.19063
## 988 72.61785
## 991 70.44544
## 994 64.09063
## 997 81.01196
## 1002 83.09800
## 1006 80.88864
## 1011 66.56119
## 1014 65.94491
## 1022 62.45891
## 1027 77.76387
## 1035 81.21623
## 1036 78.17917
## 1039 77.84228
## 1041 74.73272
## 1047 76.76778
## 1050 70.68826
## 1051 70.26622
## 1058 68.98664
## 1062 69.87859
## 1066 72.98096
## 1074 62.58279
## 1079 64.72901
## 1080 58.42432
## 1089 52.72789
## 1093 60.43136
## 1094 59.93821
## 1096 60.03466
## 1099 64.61338
## 1103 57.92276
## 1105 59.99954
## 1111 68.35948
## 1115 66.50798
## 1118 66.48528
## 1119 64.05795
## 1124 62.61022
## 1137 63.70072
## 1139 71.06561
## 1141 74.17934
## 1146 70.10478
## 1147 72.77551
## 1152 66.82886
## 1157 78.47627
## 1158 78.31439
## 1161 77.94188
## 1164 77.57724
## 1166 79.85573
## 1168 75.48242
## 1171 81.95540
## 1172 77.00966
## 1175 80.21250
## 1176 83.47097
## 1178 83.63715
## 1180 81.60848
## 1187 74.39915
## 1199 66.27350
## 1200 58.54447
## 1210 68.24230
## 1213 70.60980
## 1215 65.44742
## 1226 72.37365
## 1228 71.63007
## 1230 71.77070
## 1232 71.44366
## 1234 73.53859
## 1237 70.95676
## 1242 68.80128
## 1251 81.74908
## 1252 82.16723
## 1271 79.28824
## 1273 78.66971
## 1282 76.59033
## 1290 79.39172
## 1302 72.18958
## 1308 74.50858
## 1322 79.46708
## 1329 77.81666
## 1343 73.64361
## 1350 71.81748
## 1355 71.43616
## 1365 63.70149
## 1367 63.81420
## 1372 52.78211
## 1375 50.64488
## 1384 74.09210
## 1391 60.32075
## 1392 66.58653
## 1396 73.50889
## 1404 76.82749
## 1413 70.97077
## 1415 70.33928
## 1417 72.42024
## 1420 69.31712
## 1425 69.15294
## 1433 63.98719
## 1445 74.31894
## 1453 76.44117
## 1458 73.87289
## 1463 74.21620
## 1466 72.95992
## 1470 69.71167
## 1471 72.27778
## 1479 65.28012
## 1483 44.40123
## 1491 62.00417
## 1499 59.42746
## 1505 57.81228
## 1511 70.66425
## 1513 74.03039
## 1515 74.13309
## 1518 74.03156
## 1519 74.89908
## 1522 74.37450
## 1526 76.10020
## 1531 81.13934
## 1535 78.96978
## 1537 78.05632
## 1540 79.98241
## 1542 78.61888
## 1543 82.13737
## 1549 80.03595
## 1551 80.20399
## 1553 79.51121
## 1567 59.46084
## 1572 60.27111
## 1573 58.63110
## 1581 56.17871
## 1582 45.24143
## 1586 43.74642
## 1589 72.27284
## 1593 72.23559
## 1597 70.64191
## 1607 72.07051
## 1618 69.01550
## 1633 58.27802
## 1639 80.48554
## 1649 77.02704
## 1650 78.41154
## 1659 62.20869
## 1666 61.35165
## 1674 71.26340
## 1676 71.93883
## 1678 71.28925
## 1687 74.12743
## 1690 76.77096
## 1691 74.35092
## 1693 74.31292
## 1698 72.51517
## 1703 71.38522
## 1708 70.35378
## 1709 69.83454
## 1714 69.01766
## 1723 70.92811
## 1725 74.59687
## 1727 68.47520
## 1734 77.82207
## 1738 75.98911
## 1743 73.52955
## 1748 60.22807
## 1760 69.43011
## 1763 67.96592
## 1764 70.23886
## 1766 59.09903
## 1776 49.67722
## 1777 49.40628
## 1784 68.38165
## 1788 60.28282
## 1795 60.52830
## 1799 67.53719
## 1801 63.68714
## 1818 67.64458
## 1826 66.60507
## 1832 84.20504
## 1833 80.75648
## 1848 84.66074
## 1854 81.58015
## 1856 81.25280
## 1858 76.52578
## 1861 77.37639
## 1862 71.10876
## 1868 70.81789
## 1878 62.18695
## 1885 54.62909
## 1890 54.79334
## 1894 52.16337
## 1898 48.84572
## 1905 50.17582
## 1911 81.45713
## 1913 78.51893
## 1916 84.05204
## 1917 80.36208
## 1919 83.97371
## 1928 76.14337
## 1933 75.70497
## 1936 70.01843
## 1940 74.16504
## 1942 66.41219
## 1943 67.58376
## 1944 66.88284
## 1957 60.89326
## 1960 73.30585
## 1962 71.50394
## 1965 74.31239
## 1968 72.25169
## 1972 73.47151
## 1973 73.42822
## 1978 62.79254
## 1981 63.71125
## 1982 63.77439
## 1987 59.26406
## 1988 60.51353
## 1989 59.46951
## 1990 59.10188
## 1992 69.28675
## 1997 71.86502
## 2013 75.04512
## 2023 72.30816
## 2028 69.05994
## 2034 65.95696
## 2044 78.54676
## 2047 78.61202
## 2058 78.57927
## 2059 79.74113
## 2063 80.21992
## 2064 78.47558
## 2066 80.96229
## 2069 81.01337
## 2070 78.95487
## 2073 77.33613
## 2083 76.69285
## 2086 74.10816
## 2092 72.05113
## 2094 72.80439
## 2095 72.69141
## 2097 72.80530
## 2103 71.31606
## 2105 68.42389
## 2109 66.18064
## 2114 70.49592
## 2124 75.52770
## 2125 77.48903
## 2135 72.95187
## 2153 69.05643
## 2154 65.45010
## 2157 68.90564
## 2167 48.16775
## 2176 72.31260
## 2178 69.71304
## 2180 71.05502
## 2181 68.01170
## 2183 71.34602
## 2200 65.51069
## 2203 72.40223
## 2211 73.14440
## 2220 68.60466
## 2221 67.11558
## 2227 70.43672
## 2232 61.53878
## 2239 75.54473
## 2248 75.32969
## 2249 75.16571
## 2256 61.60326
## 2258 64.32687
## 2268 74.97930
## 2271 74.11240
## 2278 73.12376
## 2279 73.53800
## 2281 71.70544
## 2287 73.88375
## 2290 72.03015
## 2299 58.91737
## 2306 62.96140
## 2310 63.80234
## 2316 78.40795
## 2317 79.86662
## 2323 76.32631
## 2331 77.93472
## 2340 76.15935
## 2341 75.97860
## 2342 75.53683
## 2354 82.44785
## 2362 67.08579
## 2366 68.30863
## 2367 64.75274
## 2371 70.94259
## 2372 67.07289
## 2373 66.42331
## 2376 64.02547
## 2377 63.48928
## 2382 61.87313
## 2387 59.94652
## 2393 60.75624
## 2399 60.13116
## 2408 51.74584
## 2413 56.72200
## 2422 52.94270
## 2424 53.08168
## 2431 80.47557
## 2433 82.93065
## 2434 79.86608
## 2435 81.20473
## 2439 79.02208
## 2443 71.08408
## 2444 70.88130
## 2445 70.63995
## 2457 68.56457
## 2465 62.93749
## 2477 71.80044
## 2482 73.73269
## 2487 64.08091
## 2488 63.55243
## 2491 62.26392
## 2493 57.93611
## 2501 46.70820
## 2502 45.74855
## 2510 82.89974
## 2512 80.14572
## 2514 81.80502
## 2516 79.99246
## 2518 81.22974
## 2521 80.63873
## 2526 83.88032
## 2534 78.54076
## 2536 80.03437
## 2546 67.08964
## 2547 67.58613
## 2551 69.03516
## 2552 68.85413
## 2553 68.77617
## 2555 69.19757
## 2560 68.90774
## 2571 72.71689
## 2573 71.40022
## 2581 69.42250
## 2589 75.66872
## 2604 67.29214
## 2605 68.14342
## 2607 66.99834
## 2611 64.22273
## 2622 68.55977
## 2628 57.62845
## 2629 58.56526
## 2637 72.98061
## 2640 72.23984
## 2643 71.54781
## 2664 69.62246
## 2669 77.00904
## 2675 76.24912
## 2677 75.47013
## 2683 77.73642
## 2686 75.36037
## 2691 67.04733
## 2695 69.96050
## 2697 70.40811
## 2703 65.77438
## 2716 66.87861
## 2720 56.06326
## 2721 57.84550
## 2724 62.54252
## 2729 48.75268
## 2736 71.03306
## 2740 70.10523
## 2741 70.97990
## 2748 76.86509
## 2755 75.58542
## 2761 74.94314
## 2762 74.68309
## 2776 75.51017
## 2779 66.98068
## 2805 76.10658
## 2811 76.67608
## 2813 76.92180
## 2823 75.06191
## 2825 74.96602
## 2831 70.89561
## 2832 69.16266
## 2834 69.70554
## 2836 69.63792
## 2841 68.74777
## 2848 68.77698
## 2850 68.39281
## 2853 64.77474
## 2857 61.62546
## 2863 72.93319
## 2871 70.18832
## 2875 70.71543
## 2877 68.99531
## 2878 72.73195
## 2899 68.55200
## 2902 62.95071
## 2908 63.58455
## 2912 57.82892
## 2913 58.89341
## 2920 58.36194
## 2926 56.90191
## 2931 56.05016
## 2938 35.50959
MSPE = data.frame(Observed = validate$Life.expectancy,
Predicted = full.model_Preds)
MSPE$Residual = MSPE$Observed - MSPE$Predicted
MSPE$SquaredResidual = MSPE$Residual^2
sqrt(mean(MSPE$SquaredResidual))
## [1] 4.041344
# RMSE of Preliminary Model
prelim.model_Preds = predict(prelim.model, newdata = validate)
as.data.frame(prelim.model_Preds)
## prelim.model_Preds
## 1 62.04751
## 6 62.74015
## 7 62.01311
## 9 60.87087
## 10 60.04632
## 24 72.54378
## 28 72.12769
## 33 75.59255
## 35 75.69186
## 36 75.45854
## 42 72.35310
## 43 68.68529
## 48 69.30902
## 49 64.06578
## 57 61.61765
## 59 58.32458
## 60 54.00736
## 79 57.98654
## 80 57.73014
## 82 79.63243
## 105 69.82244
## 108 70.95617
## 115 84.69386
## 124 79.93350
## 129 79.47648
## 130 81.07708
## 136 77.44953
## 137 77.55651
## 151 70.62875
## 156 68.66137
## 157 69.26777
## 159 66.92714
## 164 75.16231
## 168 71.87967
## 174 73.77081
## 176 67.53821
## 182 73.01680
## 184 75.50084
## 186 75.26272
## 190 74.27318
## 193 65.75712
## 194 65.16881
## 201 63.64038
## 204 62.89307
## 206 60.16174
## 209 77.58922
## 210 77.77624
## 213 77.32595
## 218 75.73090
## 221 71.41896
## 223 74.37857
## 226 78.44514
## 232 77.37811
## 240 74.04369
## 242 80.34202
## 247 78.16179
## 258 71.53712
## 259 73.92091
## 264 72.23771
## 278 63.76620
## 285 60.82530
## 287 59.66091
## 288 59.56750
## 289 70.08372
## 296 62.84960
## 297 62.28214
## 298 61.67932
## 306 74.35705
## 307 73.92546
## 312 72.94290
## 318 71.95851
## 338 71.26691
## 339 68.21284
## 345 62.28553
## 351 43.13661
## 356 76.46245
## 368 74.70742
## 371 76.98761
## 375 75.74508
## 386 77.47407
## 402 61.89976
## 406 59.37030
## 409 59.53908
## 415 51.27583
## 418 65.77554
## 419 65.54297
## 426 58.78538
## 429 54.76492
## 430 54.31885
## 446 60.74760
## 448 63.46167
## 450 70.64083
## 451 71.86623
## 452 70.12715
## 453 63.71265
## 459 67.46548
## 460 68.48342
## 465 68.26973
## 468 65.25788
## 478 59.18480
## 480 55.81295
## 482 64.75857
## 492 57.15505
## 493 58.18234
## 503 79.44224
## 505 78.21333
## 509 76.91619
## 511 79.32108
## 513 56.44941
## 516 55.73341
## 518 53.09944
## 523 50.20713
## 527 44.61606
## 532 55.23522
## 537 52.39290
## 545 79.37909
## 555 76.83152
## 556 75.15872
## 559 75.75540
## 577 73.66414
## 580 74.77391
## 596 66.56793
## 601 62.56834
## 603 63.61184
## 614 63.69295
## 626 72.31066
## 627 75.46692
## 635 73.98462
## 642 78.09589
## 645 78.20516
## 646 78.10994
## 655 73.78264
## 658 75.07393
## 665 77.70070
## 673 72.94232
## 686 75.53046
## 698 74.16286
## 699 74.07766
## 701 71.16731
## 720 69.62599
## 729 67.01309
## 732 59.39095
## 751 80.76849
## 752 78.92487
## 758 61.11456
## 760 61.49134
## 767 55.70265
## 771 74.07551
## 774 73.41211
## 788 75.23453
## 798 68.99899
## 807 72.97247
## 816 71.37737
## 822 73.87864
## 823 71.07826
## 825 73.22622
## 835 58.68699
## 840 60.46867
## 847 60.58561
## 853 61.69966
## 858 60.32562
## 859 59.94890
## 864 50.13250
## 872 79.15186
## 876 78.74658
## 878 76.58827
## 881 76.12467
## 884 63.06514
## 894 51.31979
## 898 46.81220
## 899 76.99400
## 902 73.12936
## 904 75.54178
## 906 75.16682
## 911 73.41478
## 922 80.27118
## 925 81.18396
## 926 82.11021
## 931 80.44236
## 934 80.18120
## 935 77.06686
## 954 62.60236
## 958 58.60881
## 960 58.64063
## 961 60.30847
## 971 63.42914
## 978 58.02582
## 979 75.29856
## 988 73.20773
## 991 70.68400
## 994 61.40834
## 997 80.62307
## 1002 80.08048
## 1006 79.49370
## 1011 68.61194
## 1014 68.15617
## 1022 57.71909
## 1027 78.09903
## 1035 80.87418
## 1036 79.18271
## 1039 78.72919
## 1041 74.84569
## 1047 75.33797
## 1050 70.59330
## 1051 70.22154
## 1058 69.01271
## 1062 71.11156
## 1066 70.55320
## 1074 62.63690
## 1079 60.45734
## 1080 59.18044
## 1089 53.47888
## 1093 60.64473
## 1094 60.07679
## 1096 60.44908
## 1099 59.49710
## 1103 50.62736
## 1105 53.42487
## 1111 70.41381
## 1115 67.79249
## 1118 67.56804
## 1119 64.60817
## 1124 63.15829
## 1137 58.58878
## 1139 71.66895
## 1141 72.19383
## 1146 70.75946
## 1147 70.36730
## 1152 66.61080
## 1157 79.16379
## 1158 79.13566
## 1161 78.87585
## 1164 78.64179
## 1166 77.39672
## 1168 76.02375
## 1171 81.13517
## 1172 73.85933
## 1175 78.52508
## 1176 82.46536
## 1178 82.56970
## 1180 80.94186
## 1187 65.45253
## 1199 58.48235
## 1200 58.11811
## 1210 67.13695
## 1213 65.80898
## 1215 63.27651
## 1226 72.74053
## 1228 71.80534
## 1230 71.98866
## 1232 71.72316
## 1234 71.11688
## 1237 68.01024
## 1242 68.94863
## 1251 81.29648
## 1252 81.70755
## 1271 79.82479
## 1273 79.61455
## 1282 77.04549
## 1290 77.98968
## 1302 72.72304
## 1308 72.47036
## 1322 77.76437
## 1329 76.13708
## 1343 74.55308
## 1350 74.38138
## 1355 75.50158
## 1365 64.96213
## 1367 65.76186
## 1372 54.26662
## 1375 52.58452
## 1384 72.12196
## 1391 59.00809
## 1392 67.15506
## 1396 73.21914
## 1404 77.34870
## 1413 72.35385
## 1415 71.67630
## 1417 70.06917
## 1420 71.58933
## 1425 70.92769
## 1433 64.43723
## 1445 74.06288
## 1453 78.32276
## 1458 75.00545
## 1463 74.46083
## 1466 72.92790
## 1470 65.82822
## 1471 69.11247
## 1479 60.78913
## 1483 46.65511
## 1491 62.63645
## 1499 59.19975
## 1505 58.88704
## 1511 71.44057
## 1513 74.89710
## 1515 75.05410
## 1518 75.13557
## 1519 76.38962
## 1522 75.77770
## 1526 76.62153
## 1531 79.04264
## 1535 76.19679
## 1537 74.98451
## 1540 76.80557
## 1542 75.66110
## 1543 79.56445
## 1549 77.58153
## 1551 78.67980
## 1553 78.20545
## 1567 60.96687
## 1572 63.68871
## 1573 61.26679
## 1581 48.30744
## 1582 48.86599
## 1586 46.27855
## 1589 72.78746
## 1593 72.87107
## 1597 70.90926
## 1607 70.96574
## 1618 68.87712
## 1633 54.54648
## 1639 79.26421
## 1649 75.50561
## 1650 75.40731
## 1659 62.00759
## 1666 61.39452
## 1674 72.48643
## 1676 73.13637
## 1678 72.47859
## 1687 74.33835
## 1690 74.94975
## 1691 74.94071
## 1693 74.64113
## 1698 72.13180
## 1703 73.03832
## 1708 71.89739
## 1709 71.24756
## 1714 70.19723
## 1723 73.75528
## 1725 72.89138
## 1727 71.55247
## 1734 77.10266
## 1738 77.21049
## 1743 74.67448
## 1748 57.52865
## 1760 69.13327
## 1763 67.39674
## 1764 66.78004
## 1766 61.88833
## 1776 50.53491
## 1777 50.36187
## 1784 64.64099
## 1788 62.93321
## 1795 60.10370
## 1799 69.19289
## 1801 64.52611
## 1818 67.49483
## 1826 62.38578
## 1832 83.13001
## 1833 80.23672
## 1848 83.83490
## 1854 81.19812
## 1856 80.83301
## 1858 74.60887
## 1861 75.97548
## 1862 71.43009
## 1868 71.65170
## 1878 58.84904
## 1885 56.67129
## 1890 52.32379
## 1894 61.38740
## 1898 59.59070
## 1905 55.66816
## 1911 80.82750
## 1913 77.19936
## 1916 82.23994
## 1917 79.58043
## 1919 82.18792
## 1928 74.61271
## 1933 74.27566
## 1936 69.46350
## 1940 72.19409
## 1942 64.59846
## 1943 63.47829
## 1944 62.45727
## 1957 56.77976
## 1960 74.07804
## 1962 71.54646
## 1965 75.37850
## 1968 72.59401
## 1972 74.47719
## 1973 74.42524
## 1978 64.23629
## 1981 65.68025
## 1982 65.68229
## 1987 60.88051
## 1988 62.48008
## 1989 61.50681
## 1990 60.94473
## 1992 69.34334
## 1997 72.89579
## 2013 72.97929
## 2023 73.24491
## 2028 69.99133
## 2034 66.17806
## 2044 78.74204
## 2047 75.52220
## 2058 77.45105
## 2059 79.06787
## 2063 79.65032
## 2064 77.76517
## 2066 78.67397
## 2069 78.84478
## 2070 76.13475
## 2073 77.23079
## 2083 76.94081
## 2086 74.04688
## 2092 70.97217
## 2094 71.97966
## 2095 71.80267
## 2097 72.03819
## 2103 71.30515
## 2105 68.24437
## 2109 67.59627
## 2114 73.60107
## 2124 74.66305
## 2125 77.80029
## 2135 72.51246
## 2153 65.55233
## 2154 66.73168
## 2157 65.40877
## 2167 49.22153
## 2176 73.28557
## 2178 70.06756
## 2180 72.03613
## 2181 68.21226
## 2183 72.68687
## 2200 64.62602
## 2203 73.10303
## 2211 70.83151
## 2220 69.89080
## 2221 67.71872
## 2227 67.39980
## 2232 60.69468
## 2239 75.89906
## 2248 73.70457
## 2249 73.31292
## 2256 61.34684
## 2258 60.56800
## 2268 75.64964
## 2271 74.73798
## 2278 74.01405
## 2279 74.54092
## 2281 72.06764
## 2287 71.52878
## 2290 73.74303
## 2299 64.36599
## 2306 58.34106
## 2310 60.36200
## 2316 76.81739
## 2317 78.06954
## 2323 74.21386
## 2331 77.61756
## 2340 75.98429
## 2341 75.67840
## 2342 75.19697
## 2354 80.40589
## 2362 67.35792
## 2366 69.10351
## 2367 64.66810
## 2371 67.67417
## 2372 63.22303
## 2373 62.49513
## 2376 64.71952
## 2377 63.99749
## 2382 66.15838
## 2387 63.81202
## 2393 65.25632
## 2399 64.12764
## 2408 51.83894
## 2413 58.36693
## 2422 54.59820
## 2424 54.94063
## 2431 79.68748
## 2433 80.56607
## 2434 78.89711
## 2435 80.17912
## 2439 77.98578
## 2443 71.20514
## 2444 70.97663
## 2445 70.72752
## 2457 69.13859
## 2465 64.88896
## 2477 73.36160
## 2482 71.78522
## 2487 63.80406
## 2488 63.11294
## 2491 65.86542
## 2493 60.51172
## 2501 32.39710
## 2502 29.02388
## 2510 81.28243
## 2512 79.28858
## 2514 80.49158
## 2516 79.18636
## 2518 80.29694
## 2521 79.79639
## 2526 81.28002
## 2534 76.99245
## 2536 78.21879
## 2546 65.45017
## 2547 66.40247
## 2551 68.60276
## 2552 68.24036
## 2553 68.25479
## 2555 69.27336
## 2560 69.41234
## 2571 73.70912
## 2573 72.11650
## 2581 70.21583
## 2589 74.28042
## 2604 66.53220
## 2605 67.85868
## 2607 66.54251
## 2611 63.46676
## 2622 65.11577
## 2628 59.28358
## 2629 60.39139
## 2637 73.71352
## 2640 72.72529
## 2643 72.33015
## 2664 71.02187
## 2669 75.74250
## 2675 74.73751
## 2677 73.83212
## 2683 76.77032
## 2686 75.93142
## 2691 65.63662
## 2695 69.48819
## 2697 70.44909
## 2703 65.55380
## 2716 63.57091
## 2720 58.22294
## 2721 60.89281
## 2724 58.67744
## 2729 55.20471
## 2736 73.22824
## 2740 73.62227
## 2741 74.72896
## 2748 76.98190
## 2755 75.57685
## 2761 73.16350
## 2762 72.91418
## 2776 73.57104
## 2779 70.17855
## 2805 75.13760
## 2811 78.28783
## 2813 78.67706
## 2823 76.13417
## 2825 76.12863
## 2831 72.04199
## 2832 69.79071
## 2834 70.23141
## 2836 70.31960
## 2841 69.19583
## 2848 68.65901
## 2850 68.31365
## 2853 63.30345
## 2857 59.60136
## 2863 74.10045
## 2871 71.01946
## 2875 70.38827
## 2877 68.29369
## 2878 70.00387
## 2899 64.92794
## 2902 63.88046
## 2908 66.16869
## 2912 60.06479
## 2913 61.21525
## 2920 52.28590
## 2926 60.07957
## 2931 47.80196
## 2938 34.98594
MSPE = data.frame(Observed = validate$Life.expectancy,
Predicted = prelim.model_Preds)
MSPE$Residual = MSPE$Observed - MSPE$Predicted
MSPE$SquaredResidual = MSPE$Residual^2
sqrt(mean(MSPE$SquaredResidual))
## [1] 4.553895
# RMSE of Penalized Regression Model
glmnet.fit.model_Preds = predict(glmnet.fit.model, newdata = validate)
as.data.frame(glmnet.fit.model_Preds)
## glmnet.fit.model_Preds
## 1 62.35523
## 6 62.67281
## 7 62.02556
## 9 60.95091
## 10 60.20216
## 24 72.46052
## 28 71.86820
## 33 75.36475
## 35 75.44431
## 36 75.24006
## 42 72.24106
## 43 69.25525
## 48 69.36162
## 49 63.51371
## 57 60.24880
## 59 57.17835
## 60 53.34195
## 79 58.53527
## 80 58.55020
## 82 79.32774
## 105 69.77798
## 108 70.83771
## 115 86.76511
## 124 79.39916
## 129 78.40820
## 130 82.34625
## 136 79.08912
## 137 78.97392
## 151 70.69320
## 156 68.76666
## 157 69.27415
## 159 67.29669
## 164 74.84179
## 168 71.57347
## 174 73.59167
## 176 68.16866
## 182 72.37954
## 184 74.95010
## 186 74.71285
## 190 73.78578
## 193 66.74138
## 194 66.05704
## 201 64.17292
## 204 63.72743
## 206 61.16809
## 209 76.72258
## 210 77.14006
## 213 76.69923
## 218 75.21708
## 221 71.42340
## 223 73.87786
## 226 78.31912
## 232 77.21102
## 240 74.02955
## 242 81.42737
## 247 77.80052
## 258 71.23730
## 259 73.65344
## 264 72.18938
## 278 63.52253
## 285 60.63556
## 287 59.58281
## 288 59.47714
## 289 69.57164
## 296 63.03386
## 297 62.49877
## 298 61.92074
## 306 74.04406
## 307 73.66647
## 312 72.76389
## 318 71.85276
## 338 70.80182
## 339 68.23858
## 345 62.18508
## 351 43.37143
## 356 77.07519
## 368 76.26226
## 371 76.56820
## 375 75.16696
## 386 77.11682
## 402 61.45941
## 406 58.61864
## 409 58.22848
## 415 50.17163
## 418 65.62581
## 419 65.39585
## 426 58.99348
## 429 55.19049
## 430 54.68733
## 446 60.55634
## 448 63.13903
## 450 70.13956
## 451 71.38975
## 452 69.91174
## 453 64.42812
## 459 67.50249
## 460 68.28602
## 465 68.32670
## 468 65.56309
## 478 59.85008
## 480 57.08189
## 482 64.11351
## 492 56.75949
## 493 57.51632
## 503 79.06163
## 505 79.66638
## 509 77.28953
## 511 79.52312
## 513 57.19517
## 516 56.29178
## 518 53.80144
## 523 50.85921
## 527 46.01421
## 532 54.68946
## 537 52.21660
## 545 78.56648
## 555 76.59486
## 556 75.00549
## 559 75.39371
## 577 73.58304
## 580 74.77862
## 596 66.54503
## 601 63.03211
## 603 63.91394
## 614 63.73996
## 626 71.92421
## 627 75.12179
## 635 73.81882
## 642 77.30661
## 645 78.10023
## 646 78.03784
## 655 73.81779
## 658 74.72450
## 665 77.30149
## 673 72.55794
## 686 75.23752
## 698 74.10335
## 699 74.01085
## 701 71.05498
## 720 69.45399
## 729 66.87479
## 732 60.07936
## 751 81.15581
## 752 78.52204
## 758 61.38802
## 760 61.51828
## 767 56.31448
## 771 73.67706
## 774 73.37554
## 788 74.78726
## 798 69.38276
## 807 73.41802
## 816 71.64256
## 822 73.62246
## 823 71.08553
## 825 72.96791
## 835 59.28977
## 840 60.98289
## 847 61.19458
## 853 61.67828
## 858 60.48095
## 859 60.16882
## 864 51.68358
## 872 79.11428
## 876 78.38648
## 878 76.56100
## 881 75.42758
## 884 62.45139
## 894 48.59831
## 898 43.40617
## 899 76.34398
## 902 72.49791
## 904 74.97766
## 906 74.60198
## 911 73.02822
## 922 79.79386
## 925 81.54304
## 926 82.35672
## 931 79.33635
## 934 79.81479
## 935 76.76854
## 954 63.03703
## 958 58.99015
## 960 59.31892
## 961 60.75581
## 971 63.21927
## 978 58.56985
## 979 74.78250
## 988 72.96700
## 991 70.53276
## 994 62.53010
## 997 80.17183
## 1002 81.50884
## 1006 80.45342
## 1011 68.31777
## 1014 67.66401
## 1022 57.90557
## 1027 77.78819
## 1035 80.94096
## 1036 78.64280
## 1039 78.49026
## 1041 74.87096
## 1047 75.08753
## 1050 70.96512
## 1051 70.45774
## 1058 69.46441
## 1062 71.03218
## 1066 70.58176
## 1074 63.08215
## 1079 60.46853
## 1080 59.21566
## 1089 53.90123
## 1093 61.05004
## 1094 60.48001
## 1096 60.62696
## 1099 59.87784
## 1103 52.14602
## 1105 54.68745
## 1111 70.23187
## 1115 67.68980
## 1118 67.87530
## 1119 65.15449
## 1124 63.79555
## 1137 59.30188
## 1139 71.37714
## 1141 72.01775
## 1146 70.58978
## 1147 70.25224
## 1152 66.57904
## 1157 78.44522
## 1158 78.43655
## 1161 78.49282
## 1164 78.44898
## 1166 77.20950
## 1168 75.95647
## 1171 80.28308
## 1172 75.67696
## 1175 78.46532
## 1176 83.02110
## 1178 83.51328
## 1180 80.41397
## 1187 76.86424
## 1199 67.93528
## 1200 59.34439
## 1210 69.11898
## 1213 67.85471
## 1215 65.55985
## 1226 72.53485
## 1228 71.71368
## 1230 71.86478
## 1232 71.68896
## 1234 71.09027
## 1237 68.32637
## 1242 69.24140
## 1251 80.41282
## 1252 81.23091
## 1271 79.79233
## 1273 78.71162
## 1282 76.50598
## 1290 77.74757
## 1302 72.55741
## 1308 72.09946
## 1322 78.77234
## 1329 76.93636
## 1343 74.13195
## 1350 73.82103
## 1355 75.31217
## 1365 64.66065
## 1367 65.27891
## 1372 54.05162
## 1375 51.91388
## 1384 71.98656
## 1391 60.17238
## 1392 67.63850
## 1396 72.76455
## 1404 77.01267
## 1413 71.88503
## 1415 71.47553
## 1417 69.78353
## 1420 71.38245
## 1425 70.65312
## 1433 64.53586
## 1445 73.76308
## 1453 77.75421
## 1458 74.68188
## 1463 74.08705
## 1466 72.70416
## 1470 66.17742
## 1471 69.47638
## 1479 60.66382
## 1483 47.07460
## 1491 63.15861
## 1499 60.17387
## 1505 59.56344
## 1511 71.02558
## 1513 74.43773
## 1515 74.52710
## 1518 74.69922
## 1519 75.80935
## 1522 75.23533
## 1526 76.53255
## 1531 78.91976
## 1535 76.11176
## 1537 74.94902
## 1540 80.13168
## 1542 75.51059
## 1543 83.16560
## 1549 77.35627
## 1551 80.55692
## 1553 79.54815
## 1567 61.31707
## 1572 63.41835
## 1573 61.29370
## 1581 48.40220
## 1582 48.56379
## 1586 45.87423
## 1589 72.21067
## 1593 72.20539
## 1597 70.25714
## 1607 70.49425
## 1618 68.41792
## 1633 53.35221
## 1639 79.36694
## 1649 75.19987
## 1650 75.11462
## 1659 62.04409
## 1666 61.54582
## 1674 71.87582
## 1676 72.62368
## 1678 72.01409
## 1687 74.62851
## 1690 75.19109
## 1691 74.98493
## 1693 74.92929
## 1698 72.67401
## 1703 72.76190
## 1708 71.64255
## 1709 71.07052
## 1714 70.11444
## 1723 73.40184
## 1725 72.65599
## 1727 71.36774
## 1734 76.48865
## 1738 76.77297
## 1743 74.26801
## 1748 58.13405
## 1760 69.24024
## 1763 67.69685
## 1764 67.08738
## 1766 62.01850
## 1776 50.61248
## 1777 50.60920
## 1784 64.69463
## 1788 61.66466
## 1795 60.53489
## 1799 68.90198
## 1801 64.95204
## 1818 67.45677
## 1826 62.71831
## 1832 82.41306
## 1833 79.38917
## 1848 85.46486
## 1854 80.78034
## 1856 80.41547
## 1858 75.21800
## 1861 76.35245
## 1862 71.45206
## 1868 71.54855
## 1878 57.80144
## 1885 54.61833
## 1890 49.90218
## 1894 54.23480
## 1898 51.62041
## 1905 45.10474
## 1911 79.98329
## 1913 76.57452
## 1916 85.13421
## 1917 79.06991
## 1919 84.97856
## 1928 74.01038
## 1933 73.70868
## 1936 69.00921
## 1940 71.67282
## 1942 64.99655
## 1943 67.13559
## 1944 66.15028
## 1957 59.76032
## 1960 73.57800
## 1962 71.94438
## 1965 75.06702
## 1968 72.46101
## 1972 73.91888
## 1973 73.85226
## 1978 64.77416
## 1981 65.82613
## 1982 65.91924
## 1987 61.25242
## 1988 62.98973
## 1989 62.19473
## 1990 61.59819
## 1992 69.18092
## 1997 72.73309
## 2013 73.00292
## 2023 73.03777
## 2028 70.32740
## 2034 66.66106
## 2044 78.20216
## 2047 75.54144
## 2058 77.30343
## 2059 78.70584
## 2063 79.89950
## 2064 77.50069
## 2066 78.74326
## 2069 78.75746
## 2070 75.97575
## 2073 77.49552
## 2083 77.00806
## 2086 73.53021
## 2092 70.78816
## 2094 71.85242
## 2095 71.70495
## 2097 71.89013
## 2103 71.53264
## 2105 68.77775
## 2109 67.77464
## 2114 73.41340
## 2124 74.88595
## 2125 77.53893
## 2135 72.44087
## 2153 65.67791
## 2154 66.45439
## 2157 65.48654
## 2167 49.81977
## 2176 73.10705
## 2178 70.04012
## 2180 71.95329
## 2181 68.66021
## 2183 72.52945
## 2200 64.96874
## 2203 72.97603
## 2211 70.99680
## 2220 69.50550
## 2221 67.68752
## 2227 67.33718
## 2232 61.48351
## 2239 75.42207
## 2248 73.25116
## 2249 72.90253
## 2256 61.72547
## 2258 60.34939
## 2268 75.54048
## 2271 74.68606
## 2278 73.81167
## 2279 74.26697
## 2281 72.17479
## 2287 71.49167
## 2290 73.39858
## 2299 64.55320
## 2306 58.52873
## 2310 60.32237
## 2316 76.12449
## 2317 78.49105
## 2323 73.89636
## 2331 77.21806
## 2340 75.67262
## 2341 75.35849
## 2342 74.91151
## 2354 80.45284
## 2362 67.18831
## 2366 68.98530
## 2367 65.08357
## 2371 67.66748
## 2372 63.81601
## 2373 63.13158
## 2376 64.92395
## 2377 64.37921
## 2382 65.20497
## 2387 62.78918
## 2393 64.26199
## 2399 64.10467
## 2408 51.66414
## 2413 58.63504
## 2422 54.77072
## 2424 54.96963
## 2431 79.19734
## 2433 81.25261
## 2434 78.61229
## 2435 80.65995
## 2439 77.78635
## 2443 70.88607
## 2444 70.67801
## 2445 70.36001
## 2457 68.86671
## 2465 64.32988
## 2477 73.21233
## 2482 71.60671
## 2487 64.43217
## 2488 63.80220
## 2491 65.59910
## 2493 60.37901
## 2501 33.22834
## 2502 30.55071
## 2510 83.20023
## 2512 78.71166
## 2514 81.43079
## 2516 78.57863
## 2518 80.60074
## 2521 79.77118
## 2526 85.22183
## 2534 76.80687
## 2536 79.26561
## 2546 66.09935
## 2547 66.73031
## 2551 68.56751
## 2552 68.34669
## 2553 68.26850
## 2555 69.46776
## 2560 69.35217
## 2571 73.39960
## 2573 71.85878
## 2581 70.20186
## 2589 73.77881
## 2604 66.67901
## 2605 67.67861
## 2607 66.44856
## 2611 63.67249
## 2622 65.04234
## 2628 59.61915
## 2629 60.59862
## 2637 73.62758
## 2640 72.96254
## 2643 71.97943
## 2664 70.57169
## 2669 75.27890
## 2675 74.22948
## 2677 73.36816
## 2683 76.21472
## 2686 75.82747
## 2691 66.47059
## 2695 70.02440
## 2697 70.78222
## 2703 66.06086
## 2716 63.23758
## 2720 58.11888
## 2721 60.31296
## 2724 57.87360
## 2729 53.98317
## 2736 73.37194
## 2740 73.98535
## 2741 74.56331
## 2748 77.00322
## 2755 75.65734
## 2761 72.71380
## 2762 72.47156
## 2776 73.63193
## 2779 69.49135
## 2805 75.21417
## 2811 77.46988
## 2813 77.99561
## 2823 75.71649
## 2825 75.71845
## 2831 72.02792
## 2832 69.79575
## 2834 70.59468
## 2836 70.50710
## 2841 69.41156
## 2848 68.72073
## 2850 68.38190
## 2853 63.98863
## 2857 60.68593
## 2863 74.11210
## 2871 71.13235
## 2875 70.12300
## 2877 68.27616
## 2878 69.77831
## 2899 65.01403
## 2902 64.01116
## 2908 65.76614
## 2912 60.08619
## 2913 60.70833
## 2920 52.10569
## 2926 59.95727
## 2931 48.05421
## 2938 35.32766
MSPE = data.frame(Observed = validate$Life.expectancy,
Predicted = glmnet.fit.model_Preds)
MSPE$Residual = MSPE$Observed - MSPE$Predicted
MSPE$SquaredResidual = MSPE$Residual^2
sqrt(mean(MSPE$SquaredResidual))
## [1] 4.40931
# RMSE of Forward Selection Model
fwd.select.model_Preds = predict(fwd.select.model, newdata = validate)
as.data.frame(fwd.select.model_Preds)
## fwd.select.model_Preds
## 1 61.88016
## 6 62.60091
## 7 61.89848
## 9 60.76923
## 10 59.97893
## 24 72.56463
## 28 71.98484
## 33 75.31887
## 35 75.61679
## 36 75.38591
## 42 72.30002
## 43 69.19530
## 48 69.27844
## 49 63.68341
## 57 61.29284
## 59 58.19025
## 60 54.14158
## 79 57.55694
## 80 57.53642
## 82 79.35914
## 105 69.57951
## 108 70.91714
## 115 86.78446
## 124 79.55472
## 129 78.92157
## 130 82.22867
## 136 78.65884
## 137 78.54446
## 151 70.69050
## 156 68.91862
## 157 69.31683
## 159 67.30154
## 164 74.82904
## 168 71.40163
## 174 73.38290
## 176 67.20493
## 182 72.82476
## 184 75.41957
## 186 75.18135
## 190 74.22578
## 193 65.74364
## 194 65.26057
## 201 63.64490
## 204 63.62985
## 206 61.12785
## 209 77.14885
## 210 77.20891
## 213 76.73632
## 218 75.13378
## 221 71.11053
## 223 73.84069
## 226 78.05946
## 232 76.83324
## 240 73.64515
## 242 81.30959
## 247 77.92540
## 258 71.22752
## 259 73.69424
## 264 72.14892
## 278 63.73794
## 285 60.79425
## 287 59.74216
## 288 59.63021
## 289 69.64273
## 296 62.67862
## 297 62.10863
## 298 61.50855
## 306 74.27013
## 307 73.82745
## 312 72.83939
## 318 71.87119
## 338 71.15127
## 339 68.54094
## 345 61.95413
## 351 42.84853
## 356 76.15974
## 368 74.45014
## 371 77.20010
## 375 75.75730
## 386 76.88260
## 402 62.23488
## 406 59.24736
## 409 59.44108
## 415 51.29065
## 418 65.91020
## 419 65.68693
## 426 58.80278
## 429 54.80272
## 430 54.34650
## 446 60.53126
## 448 63.27759
## 450 70.50163
## 451 71.75453
## 452 70.25017
## 453 63.47238
## 459 67.44349
## 460 68.22986
## 465 68.15029
## 468 65.44244
## 478 59.11366
## 480 56.47767
## 482 64.78808
## 492 57.33008
## 493 58.08250
## 503 79.21774
## 505 79.42498
## 509 77.32722
## 511 79.61155
## 513 56.34735
## 516 55.72949
## 518 53.01317
## 523 50.22395
## 527 44.75651
## 532 55.09191
## 537 52.75222
## 545 79.02309
## 555 76.62484
## 556 75.11743
## 559 75.60931
## 577 73.68855
## 580 74.79326
## 596 66.56119
## 601 62.80763
## 603 63.60854
## 614 63.43946
## 626 72.15267
## 627 75.43988
## 635 73.96361
## 642 77.74630
## 645 78.00045
## 646 77.88064
## 655 73.44997
## 658 75.06109
## 665 77.61174
## 673 72.73008
## 686 75.17491
## 698 73.71910
## 699 73.64411
## 701 70.61301
## 720 69.39762
## 729 67.20580
## 732 61.25051
## 751 81.15537
## 752 78.53554
## 758 61.33658
## 760 61.46220
## 767 55.63952
## 771 73.75689
## 774 73.24614
## 788 74.92661
## 798 69.08628
## 807 73.02387
## 816 71.42533
## 822 73.85088
## 823 70.99900
## 825 73.16031
## 835 58.32086
## 840 59.89312
## 847 60.21777
## 853 61.56791
## 858 60.39259
## 859 59.99018
## 864 50.46084
## 872 78.79341
## 876 77.97053
## 878 76.18373
## 881 76.03336
## 884 63.46374
## 894 51.53898
## 898 47.13165
## 899 76.73281
## 902 73.02216
## 904 75.39593
## 906 75.01985
## 911 73.35319
## 922 79.94773
## 925 81.62569
## 926 82.48747
## 931 79.95299
## 934 79.82623
## 935 76.75929
## 954 62.52203
## 958 58.06828
## 960 58.38729
## 961 59.80792
## 971 63.20694
## 978 57.82952
## 979 75.06879
## 988 72.96888
## 991 70.59748
## 994 61.35503
## 997 80.33341
## 1002 81.37077
## 1006 80.19104
## 1011 68.44194
## 1014 68.15830
## 1022 57.66059
## 1027 78.33005
## 1035 81.07641
## 1036 78.90055
## 1039 78.61717
## 1041 74.58960
## 1047 75.14450
## 1050 70.32755
## 1051 69.78815
## 1058 68.73643
## 1062 71.10530
## 1066 70.55332
## 1074 62.49948
## 1079 60.49803
## 1080 59.18959
## 1089 53.69153
## 1093 60.98860
## 1094 60.40551
## 1096 60.37824
## 1099 59.41872
## 1103 50.85330
## 1105 53.82217
## 1111 70.11103
## 1115 67.44727
## 1118 67.55041
## 1119 64.21185
## 1124 63.47160
## 1137 58.47265
## 1139 71.51896
## 1141 72.12518
## 1146 70.68714
## 1147 70.30886
## 1152 66.51149
## 1157 78.56629
## 1158 78.53163
## 1161 78.53730
## 1164 78.25429
## 1166 77.00731
## 1168 75.69230
## 1171 80.87708
## 1172 74.92594
## 1175 78.74349
## 1176 83.25011
## 1178 83.70840
## 1180 80.79164
## 1187 66.59494
## 1199 60.06302
## 1200 59.70317
## 1210 67.66818
## 1213 66.41231
## 1215 63.91748
## 1226 72.67349
## 1228 71.74228
## 1230 71.92551
## 1232 71.77034
## 1234 71.19657
## 1237 67.85281
## 1242 68.87571
## 1251 81.03828
## 1252 81.39460
## 1271 80.29530
## 1273 79.30164
## 1282 76.99430
## 1290 77.94207
## 1302 72.78431
## 1308 72.29235
## 1322 78.96428
## 1329 76.99320
## 1343 74.54829
## 1350 73.86929
## 1355 75.19901
## 1365 64.87089
## 1367 65.76574
## 1372 54.19697
## 1375 52.66970
## 1384 72.26503
## 1391 59.22920
## 1392 67.36884
## 1396 73.31539
## 1404 77.57732
## 1413 72.33063
## 1415 71.53965
## 1417 69.88160
## 1420 71.46407
## 1425 70.81718
## 1433 64.05246
## 1445 73.66043
## 1453 77.80961
## 1458 74.74331
## 1463 74.34013
## 1466 72.93705
## 1470 65.66261
## 1471 69.02619
## 1479 60.64156
## 1483 46.61099
## 1491 62.53663
## 1499 59.53515
## 1505 58.81018
## 1511 71.47628
## 1513 74.94923
## 1515 75.12396
## 1518 75.31019
## 1519 76.30378
## 1522 75.67772
## 1526 76.14265
## 1531 78.69990
## 1535 75.96337
## 1537 74.84400
## 1540 79.79128
## 1542 75.43615
## 1543 82.83351
## 1549 77.29434
## 1551 80.26098
## 1553 79.26580
## 1567 61.71554
## 1572 63.80161
## 1573 61.46944
## 1581 48.81182
## 1582 49.08820
## 1586 46.54382
## 1589 72.68475
## 1593 72.65373
## 1597 70.64401
## 1607 70.72256
## 1618 68.57363
## 1633 55.06273
## 1639 79.59222
## 1649 75.43632
## 1650 75.33656
## 1659 61.91777
## 1666 61.55276
## 1674 72.18636
## 1676 72.87609
## 1678 72.19488
## 1687 74.31805
## 1690 74.82942
## 1691 74.60897
## 1693 74.54491
## 1698 72.14227
## 1703 72.92576
## 1708 71.82940
## 1709 71.15933
## 1714 70.10225
## 1723 73.63585
## 1725 72.80158
## 1727 71.55623
## 1734 77.10587
## 1738 76.96596
## 1743 74.55549
## 1748 57.64071
## 1760 69.15791
## 1763 67.42422
## 1764 66.85964
## 1766 62.02374
## 1776 50.87072
## 1777 50.93050
## 1784 64.53099
## 1788 62.90688
## 1795 60.28005
## 1799 69.07827
## 1801 64.52680
## 1818 67.38104
## 1826 62.46970
## 1832 82.75603
## 1833 79.64282
## 1848 85.57769
## 1854 80.96418
## 1856 80.58801
## 1858 74.66297
## 1861 75.81871
## 1862 71.56826
## 1868 71.64512
## 1878 58.85450
## 1885 56.72476
## 1890 52.98176
## 1894 61.60271
## 1898 59.78480
## 1905 56.12052
## 1911 80.45689
## 1913 76.97365
## 1916 85.26710
## 1917 79.48120
## 1919 85.11358
## 1928 74.53978
## 1933 74.15574
## 1936 69.34731
## 1940 72.04356
## 1942 64.71473
## 1943 63.28890
## 1944 62.46637
## 1957 57.19649
## 1960 73.64775
## 1962 71.32228
## 1965 75.21317
## 1968 72.50694
## 1972 74.16542
## 1973 74.11736
## 1978 64.50335
## 1981 65.69236
## 1982 65.72388
## 1987 60.92420
## 1988 62.64524
## 1989 61.81834
## 1990 61.08612
## 1992 69.31911
## 1997 72.66652
## 2013 73.02938
## 2023 73.18288
## 2028 69.91458
## 2034 66.06496
## 2044 78.15492
## 2047 75.47033
## 2058 77.34027
## 2059 78.69104
## 2063 79.77002
## 2064 77.37496
## 2066 78.57620
## 2069 78.63052
## 2070 75.77235
## 2073 77.91669
## 2083 77.47921
## 2086 73.99287
## 2092 70.56463
## 2094 71.62948
## 2095 71.44192
## 2097 71.70504
## 2103 71.29068
## 2105 67.80231
## 2109 67.02805
## 2114 73.18275
## 2124 74.78229
## 2125 77.51814
## 2135 72.19091
## 2153 65.84937
## 2154 66.73110
## 2157 65.19512
## 2167 49.06266
## 2176 72.79351
## 2178 69.44111
## 2180 71.54476
## 2181 67.57994
## 2183 72.20464
## 2200 64.45209
## 2203 73.18058
## 2211 70.72998
## 2220 69.83876
## 2221 67.95340
## 2227 67.19343
## 2232 60.85635
## 2239 75.84006
## 2248 73.61203
## 2249 73.22592
## 2256 62.00051
## 2258 60.75805
## 2268 75.42939
## 2271 74.47489
## 2278 73.75898
## 2279 74.31473
## 2281 72.20673
## 2287 71.53650
## 2290 73.34959
## 2299 64.63164
## 2306 58.26886
## 2310 60.27569
## 2316 76.74036
## 2317 79.00761
## 2323 74.33534
## 2331 77.24908
## 2340 75.61101
## 2341 75.33396
## 2342 74.86726
## 2354 80.46990
## 2362 67.16850
## 2366 69.17440
## 2367 64.57168
## 2371 67.80468
## 2372 63.55399
## 2373 62.49774
## 2376 64.84428
## 2377 64.30323
## 2382 66.18064
## 2387 63.55954
## 2393 65.07776
## 2399 64.00996
## 2408 51.39364
## 2413 58.32911
## 2422 54.52531
## 2424 54.86785
## 2431 79.40929
## 2433 81.21631
## 2434 78.57848
## 2435 80.52530
## 2439 77.64752
## 2443 71.10625
## 2444 70.87978
## 2445 70.60551
## 2457 69.11885
## 2465 64.90452
## 2477 73.19001
## 2482 71.59412
## 2487 63.69394
## 2488 63.01528
## 2491 65.87162
## 2493 60.49148
## 2501 32.20767
## 2502 29.45742
## 2510 83.36750
## 2512 79.05783
## 2514 81.66751
## 2516 78.97223
## 2518 80.89302
## 2521 80.11334
## 2526 85.05551
## 2534 76.73668
## 2536 79.07360
## 2546 65.51354
## 2547 66.22872
## 2551 68.55059
## 2552 68.17821
## 2553 68.19443
## 2555 69.61042
## 2560 69.50348
## 2571 73.41186
## 2573 71.81726
## 2581 69.93038
## 2589 74.24682
## 2604 66.70458
## 2605 67.73614
## 2607 66.43263
## 2611 63.42605
## 2622 65.13076
## 2628 59.30153
## 2629 60.42056
## 2637 73.98137
## 2640 73.28488
## 2643 72.27642
## 2664 70.70485
## 2669 75.67404
## 2675 74.66027
## 2677 73.75040
## 2683 76.51511
## 2686 75.94979
## 2691 65.54691
## 2695 69.71027
## 2697 70.54401
## 2703 65.53402
## 2716 63.63255
## 2720 57.88117
## 2721 60.67762
## 2724 58.55200
## 2729 55.61200
## 2736 72.88166
## 2740 74.12112
## 2741 74.56128
## 2748 77.43010
## 2755 75.99202
## 2761 73.05869
## 2762 72.80454
## 2776 73.19628
## 2779 70.01113
## 2805 74.83855
## 2811 77.90332
## 2813 78.29970
## 2823 75.91073
## 2825 75.83854
## 2831 71.99738
## 2832 69.68901
## 2834 70.45115
## 2836 70.40491
## 2841 69.33142
## 2848 68.64866
## 2850 68.28396
## 2853 63.39802
## 2857 59.60178
## 2863 73.87062
## 2871 70.78825
## 2875 70.01921
## 2877 67.85244
## 2878 69.60898
## 2899 64.72463
## 2902 63.80668
## 2908 66.14400
## 2912 60.08483
## 2913 61.15184
## 2920 52.66012
## 2926 59.87781
## 2931 47.84722
## 2938 35.07525
MSPE = data.frame(Observed = validate$Life.expectancy,
Predicted = fwd.select.model_Preds)
MSPE$Residual = MSPE$Observed - MSPE$Predicted
MSPE$SquaredResidual = MSPE$Residual^2
sqrt(mean(MSPE$SquaredResidual))
## [1] 4.528587
# RMSE of Backward Selection Model
bck.select.model_Preds = predict(bck.select.model, newdata = validate)
as.data.frame(bck.select.model_Preds)
## bck.select.model_Preds
## 1 62.35462
## 6 62.67258
## 7 62.02852
## 9 60.94398
## 10 60.19891
## 24 72.45860
## 28 71.86594
## 33 75.36348
## 35 75.44416
## 36 75.23874
## 42 72.24103
## 43 69.26258
## 48 69.35749
## 49 63.49404
## 57 60.22242
## 59 57.14034
## 60 53.30397
## 79 58.52821
## 80 58.54316
## 82 79.32152
## 105 69.77544
## 108 70.84197
## 115 86.76667
## 124 79.38567
## 129 78.40651
## 130 82.34958
## 136 79.08498
## 137 78.96737
## 151 70.69176
## 156 68.76962
## 157 69.27981
## 159 67.29576
## 164 74.84303
## 168 71.56387
## 174 73.58987
## 176 68.15669
## 182 72.37043
## 184 74.95051
## 186 74.71370
## 190 73.78694
## 193 66.73356
## 194 66.04637
## 201 64.15960
## 204 63.71935
## 206 61.13064
## 209 76.72039
## 210 77.13825
## 213 76.69602
## 218 75.21236
## 221 71.42197
## 223 73.87327
## 226 78.31535
## 232 77.20625
## 240 74.02606
## 242 81.42170
## 247 77.79355
## 258 71.22625
## 259 73.65063
## 264 72.18683
## 278 63.51290
## 285 60.62594
## 287 59.59634
## 288 59.48417
## 289 69.57409
## 296 63.03187
## 297 62.49652
## 298 61.91832
## 306 74.03872
## 307 73.66055
## 312 72.75561
## 318 71.84437
## 338 70.80034
## 339 68.23957
## 345 62.18305
## 351 43.36736
## 356 77.06810
## 368 76.24421
## 371 76.56451
## 375 75.16300
## 386 77.11614
## 402 61.44637
## 406 58.61371
## 409 58.21016
## 415 50.16276
## 418 65.61681
## 419 65.38744
## 426 58.99119
## 429 55.18062
## 430 54.68029
## 446 60.55741
## 448 63.14302
## 450 70.13034
## 451 71.38501
## 452 69.90851
## 453 64.42315
## 459 67.49976
## 460 68.28299
## 465 68.31591
## 468 65.56184
## 478 59.85027
## 480 57.12582
## 482 64.09909
## 492 56.74010
## 493 57.49828
## 503 79.06376
## 505 79.67062
## 509 77.27992
## 511 79.52262
## 513 57.18926
## 516 56.28456
## 518 53.79045
## 523 50.85396
## 527 46.01103
## 532 54.66775
## 537 52.19121
## 545 78.56341
## 555 76.59165
## 556 75.00360
## 559 75.39030
## 577 73.58023
## 580 74.77557
## 596 66.54164
## 601 63.02448
## 603 63.91157
## 614 63.73233
## 626 71.91282
## 627 75.12351
## 635 73.81789
## 642 77.30548
## 645 78.09916
## 646 78.03660
## 655 73.81563
## 658 74.72538
## 665 77.29492
## 673 72.55671
## 686 75.23513
## 698 74.10135
## 699 74.00901
## 701 71.04313
## 720 69.44588
## 729 66.86392
## 732 60.74240
## 751 81.15443
## 752 78.51994
## 758 61.39023
## 760 61.51932
## 767 56.31361
## 771 73.67512
## 774 73.37162
## 788 74.78516
## 798 69.38020
## 807 73.41003
## 816 71.63466
## 822 73.61984
## 823 71.08459
## 825 72.96525
## 835 59.29213
## 840 60.97696
## 847 61.18111
## 853 61.67355
## 858 60.47669
## 859 60.16422
## 864 51.67610
## 872 79.10985
## 876 78.38016
## 878 76.55609
## 881 75.42474
## 884 62.45854
## 894 48.53334
## 898 43.33252
## 899 76.34330
## 902 72.48620
## 904 74.97549
## 906 74.59919
## 911 73.02648
## 922 79.79177
## 925 81.54114
## 926 82.35379
## 931 79.33333
## 934 79.81572
## 935 76.81801
## 954 63.03154
## 958 58.97893
## 960 59.31397
## 961 60.76936
## 971 63.21510
## 978 58.55634
## 979 74.78260
## 988 72.96758
## 991 70.53338
## 994 62.51864
## 997 80.17978
## 1002 81.50607
## 1006 80.44638
## 1011 68.30543
## 1014 67.65703
## 1022 57.89032
## 1027 77.78751
## 1035 80.94064
## 1036 78.64197
## 1039 78.48846
## 1041 74.87124
## 1047 75.08367
## 1050 70.95014
## 1051 70.44264
## 1058 69.45061
## 1062 71.02765
## 1066 70.57669
## 1074 63.06950
## 1079 60.45670
## 1080 59.20053
## 1089 53.90791
## 1093 61.04750
## 1094 60.47736
## 1096 60.62311
## 1099 59.87380
## 1103 52.14165
## 1105 54.67268
## 1111 70.23085
## 1115 67.68121
## 1118 67.87354
## 1119 65.14964
## 1124 63.79384
## 1137 59.29419
## 1139 71.37365
## 1141 72.01712
## 1146 70.58759
## 1147 70.24956
## 1152 66.56889
## 1157 78.44316
## 1158 78.43451
## 1161 78.49067
## 1164 78.44705
## 1166 77.20849
## 1168 75.95470
## 1171 80.27936
## 1172 75.66609
## 1175 78.46511
## 1176 83.01998
## 1178 83.51246
## 1180 80.41211
## 1187 77.09365
## 1199 67.82032
## 1200 59.16509
## 1210 69.14667
## 1213 67.88119
## 1215 65.61874
## 1226 72.53585
## 1228 71.71418
## 1230 71.86323
## 1232 71.72372
## 1234 71.13230
## 1237 68.32758
## 1242 69.25836
## 1251 80.40907
## 1252 81.22775
## 1271 79.79316
## 1273 78.71110
## 1282 76.50538
## 1290 77.75363
## 1302 72.55530
## 1308 72.09430
## 1322 78.81115
## 1329 77.01857
## 1343 74.13519
## 1350 73.80640
## 1355 75.30400
## 1365 64.64110
## 1367 65.27001
## 1372 54.03404
## 1375 51.89006
## 1384 71.98264
## 1391 60.15507
## 1392 67.63273
## 1396 72.75361
## 1404 77.01100
## 1413 71.88217
## 1415 71.47249
## 1417 69.77309
## 1420 71.37821
## 1425 70.64685
## 1433 64.52877
## 1445 73.75042
## 1453 77.75068
## 1458 74.67943
## 1463 74.09041
## 1466 72.70940
## 1470 66.16192
## 1471 69.47210
## 1479 60.66008
## 1483 47.07432
## 1491 63.15628
## 1499 60.16438
## 1505 59.55807
## 1511 71.01771
## 1513 74.43878
## 1515 74.52561
## 1518 74.70841
## 1519 75.80776
## 1522 75.23247
## 1526 76.51939
## 1531 78.91634
## 1535 76.10998
## 1537 74.94781
## 1540 80.12474
## 1542 75.49953
## 1543 83.16913
## 1549 77.35543
## 1551 80.55740
## 1553 79.54749
## 1567 61.54786
## 1572 63.41153
## 1573 61.27849
## 1581 48.39021
## 1582 48.55295
## 1586 45.85587
## 1589 72.21078
## 1593 72.20417
## 1597 70.25472
## 1607 70.49857
## 1618 68.42102
## 1633 53.34012
## 1639 79.36923
## 1649 75.19958
## 1650 75.11395
## 1659 62.04003
## 1666 61.54115
## 1674 71.86737
## 1676 72.61960
## 1678 72.01020
## 1687 74.62398
## 1690 75.18524
## 1691 74.97859
## 1693 74.92191
## 1698 72.66445
## 1703 72.76650
## 1708 71.64646
## 1709 71.07390
## 1714 70.11499
## 1723 73.39636
## 1725 72.65103
## 1727 71.36375
## 1734 76.48813
## 1738 76.77129
## 1743 74.26893
## 1748 58.13335
## 1760 69.26311
## 1763 67.70459
## 1764 67.11271
## 1766 61.99958
## 1776 50.62335
## 1777 50.69692
## 1784 64.69357
## 1788 61.64659
## 1795 60.52777
## 1799 68.90841
## 1801 64.95535
## 1818 67.46596
## 1826 62.76775
## 1832 82.42364
## 1833 79.37875
## 1848 85.46744
## 1854 80.77766
## 1856 80.41263
## 1858 75.20294
## 1861 76.34713
## 1862 71.45021
## 1868 71.54606
## 1878 57.81264
## 1885 54.60249
## 1890 50.08938
## 1894 54.14869
## 1898 51.54606
## 1905 45.05831
## 1911 79.98016
## 1913 76.56510
## 1916 85.13770
## 1917 79.07035
## 1919 84.98089
## 1928 74.01153
## 1933 73.70879
## 1936 69.00111
## 1940 71.67275
## 1942 64.98905
## 1943 67.08865
## 1944 66.10422
## 1957 59.71682
## 1960 73.57598
## 1962 71.94275
## 1965 75.06636
## 1968 72.45881
## 1972 73.91649
## 1973 73.85048
## 1978 64.76960
## 1981 65.81772
## 1982 65.91139
## 1987 61.24678
## 1988 62.99977
## 1989 62.25980
## 1990 61.60859
## 1992 69.16985
## 1997 72.73130
## 2013 72.99776
## 2023 73.02816
## 2028 70.33314
## 2034 66.63676
## 2044 78.19915
## 2047 75.54013
## 2058 77.29215
## 2059 78.70457
## 2063 79.89780
## 2064 77.49870
## 2066 78.74053
## 2069 78.75379
## 2070 75.96335
## 2073 77.49748
## 2083 77.01004
## 2086 73.53124
## 2092 70.77571
## 2094 71.84462
## 2095 71.69656
## 2097 71.88142
## 2103 71.65026
## 2105 68.76832
## 2109 67.76649
## 2114 73.41241
## 2124 74.90091
## 2125 77.53650
## 2135 72.43771
## 2153 65.66924
## 2154 66.44439
## 2157 65.47851
## 2167 49.80968
## 2176 73.10450
## 2178 70.02914
## 2180 71.94906
## 2181 68.65326
## 2183 72.52473
## 2200 64.94800
## 2203 72.97717
## 2211 70.99393
## 2220 69.50532
## 2221 67.68754
## 2227 67.33467
## 2232 61.47882
## 2239 75.42535
## 2248 73.25317
## 2249 72.90363
## 2256 61.71697
## 2258 60.33987
## 2268 75.53368
## 2271 74.67985
## 2278 73.81092
## 2279 74.26704
## 2281 72.17354
## 2287 71.48768
## 2290 73.39197
## 2299 64.55485
## 2306 58.50975
## 2310 60.31839
## 2316 76.11899
## 2317 78.48562
## 2323 73.88390
## 2331 77.21717
## 2340 75.66992
## 2341 75.35572
## 2342 74.90766
## 2354 80.45045
## 2362 67.17573
## 2366 68.98131
## 2367 65.07847
## 2371 67.66409
## 2372 63.81601
## 2373 63.12474
## 2376 64.92034
## 2377 64.37443
## 2382 65.25402
## 2387 62.76636
## 2393 64.25975
## 2399 64.14544
## 2408 51.65729
## 2413 58.63147
## 2422 54.75859
## 2424 54.95667
## 2431 79.19795
## 2433 81.25336
## 2434 78.61159
## 2435 80.65963
## 2439 77.78329
## 2443 70.89464
## 2444 70.68833
## 2445 70.36139
## 2457 68.93174
## 2465 64.31445
## 2477 73.21199
## 2482 71.60543
## 2487 64.42332
## 2488 63.79459
## 2491 65.59690
## 2493 60.37180
## 2501 33.22684
## 2502 30.55331
## 2510 83.20544
## 2512 78.71251
## 2514 81.43195
## 2516 78.57886
## 2518 80.60097
## 2521 79.77009
## 2526 85.23042
## 2534 76.80133
## 2536 79.26072
## 2546 66.09816
## 2547 66.72814
## 2551 68.56835
## 2552 68.34675
## 2553 68.26763
## 2555 69.46605
## 2560 69.34749
## 2571 73.39456
## 2573 71.86868
## 2581 70.21185
## 2589 73.77922
## 2604 66.67454
## 2605 67.67294
## 2607 66.44248
## 2611 63.66643
## 2622 65.03378
## 2628 59.61284
## 2629 60.59139
## 2637 73.62663
## 2640 72.96219
## 2643 71.96553
## 2664 70.56827
## 2669 75.28162
## 2675 74.22921
## 2677 73.36785
## 2683 76.21580
## 2686 75.82648
## 2691 66.46803
## 2695 70.05103
## 2697 70.83960
## 2703 66.04604
## 2716 63.21850
## 2720 58.09803
## 2721 60.29192
## 2724 57.86558
## 2729 54.13226
## 2736 73.36943
## 2740 74.15144
## 2741 74.56966
## 2748 77.00620
## 2755 75.65670
## 2761 72.71364
## 2762 72.47140
## 2776 73.63033
## 2779 69.46871
## 2805 75.21605
## 2811 77.46735
## 2813 77.99503
## 2823 75.71359
## 2825 75.71624
## 2831 72.02366
## 2832 69.78290
## 2834 70.58914
## 2836 70.50319
## 2841 69.40338
## 2848 68.71620
## 2850 68.37612
## 2853 63.97558
## 2857 60.67069
## 2863 74.10814
## 2871 71.12730
## 2875 70.12039
## 2877 68.27702
## 2878 69.77766
## 2899 65.01108
## 2902 64.05649
## 2908 65.75373
## 2912 60.13204
## 2913 60.69048
## 2920 52.18878
## 2926 59.94256
## 2931 48.04391
## 2938 35.32895
MSPE = data.frame(Observed = validate$Life.expectancy,
Predicted = bck.select.model_Preds)
MSPE$Residual = MSPE$Observed - MSPE$Predicted
MSPE$SquaredResidual = MSPE$Residual^2
sqrt(mean(MSPE$SquaredResidual))
## [1] 4.412429
# RMSE of Backward Selection Model
sw.select.model_Preds = predict(sw.select.model, newdata = validate)
as.data.frame(sw.select.model_Preds)
## sw.select.model_Preds
## 1 61.31254
## 6 61.86068
## 7 61.12008
## 9 60.37020
## 10 59.47158
## 24 72.64839
## 28 71.93454
## 33 75.36283
## 35 75.46759
## 36 75.37724
## 42 72.65004
## 43 69.64285
## 48 69.57267
## 49 63.57112
## 57 61.47412
## 59 58.33431
## 60 54.19348
## 79 57.62813
## 80 57.67492
## 82 79.64893
## 105 69.80748
## 108 70.99819
## 115 86.68206
## 124 79.25224
## 129 78.96166
## 130 81.68167
## 136 79.47028
## 137 79.37008
## 151 70.71504
## 156 68.65508
## 157 69.20891
## 159 67.53956
## 164 74.66161
## 168 71.12654
## 174 73.50082
## 176 67.47864
## 182 73.06985
## 184 75.84213
## 186 75.50895
## 190 74.53136
## 193 65.57621
## 194 65.50276
## 201 63.82117
## 204 64.10597
## 206 61.62822
## 209 77.19218
## 210 77.00608
## 213 76.64391
## 218 75.21456
## 221 71.14486
## 223 73.87927
## 226 78.20041
## 232 76.91327
## 240 73.68579
## 242 82.16249
## 247 78.69179
## 258 71.17502
## 259 73.73655
## 264 72.20087
## 278 63.78275
## 285 60.84011
## 287 59.76637
## 288 59.70083
## 289 69.49776
## 296 62.46875
## 297 61.98637
## 298 61.46454
## 306 74.30248
## 307 73.90796
## 312 73.05325
## 318 71.84380
## 338 71.17880
## 339 68.58751
## 345 62.11091
## 351 42.90841
## 356 75.86537
## 368 74.28786
## 371 77.66841
## 375 76.15484
## 386 76.58310
## 402 62.30147
## 406 58.90805
## 409 59.16151
## 415 51.27319
## 418 65.64221
## 419 65.31184
## 426 57.90332
## 429 54.78204
## 430 54.33070
## 446 60.60161
## 448 63.16665
## 450 70.57689
## 451 71.94907
## 452 70.43284
## 453 63.54469
## 459 67.54436
## 460 68.17785
## 465 68.15177
## 468 65.30189
## 478 58.91482
## 480 56.37811
## 482 65.01257
## 492 57.46386
## 493 58.13201
## 503 78.56883
## 505 79.08159
## 509 76.84823
## 511 79.28606
## 513 56.23883
## 516 55.91381
## 518 53.11466
## 523 50.32862
## 527 44.96523
## 532 55.28718
## 537 53.06476
## 545 79.13603
## 555 76.59488
## 556 75.08291
## 559 75.59831
## 577 73.80322
## 580 74.71029
## 596 66.33006
## 601 62.86577
## 603 63.73402
## 614 63.85939
## 626 72.15457
## 627 75.03440
## 635 73.72764
## 642 77.83605
## 645 77.82220
## 646 77.69870
## 655 73.47745
## 658 75.16755
## 665 78.31526
## 673 72.62548
## 686 75.09786
## 698 73.70544
## 699 73.60374
## 701 70.42455
## 720 69.32613
## 729 67.36773
## 732 61.40362
## 751 80.82148
## 752 78.17081
## 758 60.87117
## 760 60.99628
## 767 55.53712
## 771 73.79577
## 774 73.51803
## 788 74.49812
## 798 69.11399
## 807 73.15087
## 816 71.43912
## 822 73.80801
## 823 70.91990
## 825 73.08415
## 835 58.14052
## 840 60.00250
## 847 60.63093
## 853 61.77587
## 858 60.54889
## 859 60.20245
## 864 50.55978
## 872 78.84691
## 876 78.15175
## 878 76.40616
## 881 76.24750
## 884 63.57263
## 894 51.53570
## 898 47.13868
## 899 76.82966
## 902 73.23901
## 904 75.70512
## 906 75.39871
## 911 73.75797
## 922 79.72354
## 925 81.44363
## 926 82.35267
## 931 80.03631
## 934 79.14505
## 935 75.98008
## 954 63.04209
## 958 58.31915
## 960 58.73982
## 961 60.10887
## 971 63.11651
## 978 58.00881
## 979 75.13463
## 988 72.63442
## 991 70.23069
## 994 61.26336
## 997 79.69504
## 1002 82.26923
## 1006 81.03734
## 1011 68.41131
## 1014 68.26109
## 1022 57.74325
## 1027 78.55835
## 1035 80.73031
## 1036 78.53457
## 1039 78.33173
## 1041 74.28273
## 1047 75.16422
## 1050 70.53398
## 1051 69.95496
## 1058 68.78202
## 1062 71.07574
## 1066 70.47418
## 1074 62.47697
## 1079 60.55660
## 1080 59.23459
## 1089 53.88346
## 1093 60.95098
## 1094 60.39188
## 1096 60.20381
## 1099 59.30881
## 1103 50.81755
## 1105 53.95771
## 1111 69.93443
## 1115 67.26981
## 1118 67.59675
## 1119 64.09032
## 1124 63.23573
## 1137 58.44968
## 1139 71.57311
## 1141 71.70188
## 1146 70.35454
## 1147 70.04827
## 1152 66.25270
## 1157 78.40419
## 1158 78.33952
## 1161 78.39339
## 1164 78.02829
## 1166 76.69982
## 1168 75.57420
## 1171 81.03301
## 1172 74.56610
## 1175 78.58271
## 1176 83.05251
## 1178 83.54917
## 1180 80.49704
## 1187 66.26556
## 1199 59.87945
## 1200 59.50136
## 1210 68.12472
## 1213 66.85990
## 1215 64.38125
## 1226 72.58774
## 1228 71.69277
## 1230 71.89069
## 1232 71.80676
## 1234 71.35785
## 1237 67.77436
## 1242 69.09360
## 1251 81.19967
## 1252 81.28612
## 1271 80.21750
## 1273 79.13731
## 1282 76.91238
## 1290 77.66703
## 1302 72.90244
## 1308 72.56794
## 1322 78.69540
## 1329 76.79247
## 1343 74.12769
## 1350 74.04066
## 1355 75.63821
## 1365 64.80960
## 1367 65.80459
## 1372 54.29529
## 1375 52.81261
## 1384 73.03275
## 1391 58.69375
## 1392 67.13245
## 1396 73.59863
## 1404 78.17953
## 1413 72.24351
## 1415 71.51715
## 1417 69.69562
## 1420 71.36071
## 1425 70.98457
## 1433 64.18093
## 1445 73.68290
## 1453 77.81824
## 1458 74.78913
## 1463 74.17268
## 1466 72.57477
## 1470 65.27684
## 1471 68.70382
## 1479 59.75653
## 1483 46.33876
## 1491 62.47954
## 1499 60.20582
## 1505 58.61493
## 1511 71.59448
## 1513 75.40465
## 1515 75.66649
## 1518 75.75766
## 1519 76.54564
## 1522 76.07329
## 1526 76.02355
## 1531 78.75529
## 1535 76.00141
## 1537 74.90244
## 1540 79.90152
## 1542 75.21847
## 1543 83.01678
## 1549 77.05971
## 1551 80.23258
## 1553 79.22638
## 1567 61.73791
## 1572 62.99773
## 1573 62.03671
## 1581 48.60083
## 1582 48.89026
## 1586 46.51233
## 1589 72.87261
## 1593 72.83679
## 1597 70.86304
## 1607 70.22864
## 1618 68.08147
## 1633 54.93383
## 1639 79.20711
## 1649 75.36990
## 1650 75.30957
## 1659 62.13795
## 1666 61.71266
## 1674 72.20605
## 1676 73.04926
## 1678 72.32636
## 1687 74.36244
## 1690 74.77862
## 1691 74.53251
## 1693 74.60022
## 1698 72.27944
## 1703 72.01464
## 1708 71.01234
## 1709 70.33681
## 1714 69.75453
## 1723 73.78950
## 1725 72.89679
## 1727 71.59880
## 1734 77.11375
## 1738 76.90174
## 1743 74.22899
## 1748 57.37613
## 1760 69.21279
## 1763 67.57486
## 1764 67.03758
## 1766 61.84943
## 1776 50.89472
## 1777 50.88194
## 1784 64.87114
## 1788 63.29281
## 1795 60.68464
## 1799 68.61444
## 1801 64.09670
## 1818 67.09049
## 1826 62.29334
## 1832 82.07041
## 1833 78.87920
## 1848 85.17440
## 1854 80.78893
## 1856 80.42205
## 1858 74.38904
## 1861 75.64667
## 1862 71.68335
## 1868 71.56586
## 1878 58.68658
## 1885 56.37659
## 1890 52.65918
## 1894 61.45545
## 1898 59.92259
## 1905 56.13090
## 1911 80.58332
## 1913 76.49710
## 1916 85.18931
## 1917 79.10854
## 1919 85.12569
## 1928 74.87271
## 1933 74.54710
## 1936 69.73593
## 1940 72.36344
## 1942 65.11809
## 1943 63.00037
## 1944 62.62807
## 1957 57.33968
## 1960 73.65427
## 1962 70.84298
## 1965 74.88055
## 1968 72.50552
## 1972 73.94457
## 1973 73.79222
## 1978 64.72270
## 1981 65.94672
## 1982 65.95549
## 1987 60.46708
## 1988 62.49506
## 1989 61.52545
## 1990 60.92447
## 1992 69.31676
## 1997 72.23169
## 2013 73.21732
## 2023 73.41486
## 2028 70.12424
## 2034 66.29734
## 2044 78.10016
## 2047 75.47164
## 2058 76.84383
## 2059 78.26930
## 2063 79.34257
## 2064 76.95182
## 2066 78.10807
## 2069 78.27846
## 2070 75.32316
## 2073 78.51540
## 2083 77.87655
## 2086 74.48572
## 2092 70.38743
## 2094 71.52612
## 2095 71.40956
## 2097 71.73391
## 2103 71.53259
## 2105 68.41266
## 2109 65.87473
## 2114 72.74333
## 2124 74.98463
## 2125 77.60856
## 2135 72.43028
## 2153 65.59041
## 2154 66.40000
## 2157 64.86293
## 2167 49.14686
## 2176 72.57166
## 2178 69.27872
## 2180 71.48630
## 2181 67.44653
## 2183 72.17232
## 2200 64.83381
## 2203 73.12338
## 2211 70.99750
## 2220 69.24064
## 2221 67.56516
## 2227 66.85452
## 2232 61.48365
## 2239 76.17322
## 2248 73.77452
## 2249 73.41836
## 2256 62.19828
## 2258 60.76470
## 2268 76.19613
## 2271 75.11156
## 2278 73.47617
## 2279 73.93394
## 2281 72.22735
## 2287 71.89170
## 2290 73.67132
## 2299 63.73075
## 2306 58.80776
## 2310 59.31357
## 2316 76.95273
## 2317 79.34366
## 2323 74.60529
## 2331 76.97082
## 2340 75.47058
## 2341 75.21769
## 2342 74.94700
## 2354 80.30245
## 2362 67.13412
## 2366 69.22966
## 2367 64.28314
## 2371 67.72325
## 2372 63.32371
## 2373 62.45839
## 2376 64.73930
## 2377 64.51155
## 2382 66.06369
## 2387 63.37454
## 2393 64.92647
## 2399 63.64869
## 2408 50.94562
## 2413 58.69565
## 2422 54.47104
## 2424 54.81082
## 2431 79.01508
## 2433 80.99679
## 2434 78.34870
## 2435 80.36267
## 2439 77.58031
## 2443 71.32606
## 2444 71.06977
## 2445 70.86095
## 2457 69.24783
## 2465 64.51969
## 2477 73.06932
## 2482 71.59111
## 2487 63.62545
## 2488 62.76460
## 2491 65.41498
## 2493 60.06364
## 2501 32.37364
## 2502 29.73596
## 2510 82.82797
## 2512 78.56581
## 2514 81.43518
## 2516 78.53064
## 2518 80.55357
## 2521 79.90662
## 2526 84.74632
## 2534 77.38800
## 2536 79.90994
## 2546 65.75181
## 2547 66.41709
## 2551 68.63684
## 2552 68.26154
## 2553 68.27699
## 2555 69.52503
## 2560 69.50428
## 2571 73.61388
## 2573 71.95163
## 2581 70.16864
## 2589 74.18295
## 2604 67.28655
## 2605 68.29719
## 2607 67.00868
## 2611 64.02532
## 2622 65.20485
## 2628 59.34435
## 2629 60.39302
## 2637 74.34492
## 2640 73.68696
## 2643 72.33173
## 2664 70.84211
## 2669 75.52914
## 2675 74.72938
## 2677 73.80591
## 2683 76.61679
## 2686 76.08326
## 2691 65.48771
## 2695 69.80535
## 2697 70.64635
## 2703 66.20598
## 2716 63.38088
## 2720 57.01987
## 2721 60.29151
## 2724 57.95186
## 2729 55.39864
## 2736 72.64951
## 2740 74.19290
## 2741 74.58381
## 2748 77.80506
## 2755 76.49140
## 2761 73.53041
## 2762 73.28412
## 2776 73.03037
## 2779 69.97188
## 2805 73.59070
## 2811 77.99801
## 2813 77.97801
## 2823 75.90697
## 2825 75.67820
## 2831 72.05558
## 2832 69.71685
## 2834 70.50965
## 2836 70.49518
## 2841 69.43840
## 2848 68.82238
## 2850 68.60704
## 2853 63.80262
## 2857 59.99712
## 2863 74.03634
## 2871 70.94285
## 2875 69.86667
## 2877 67.44417
## 2878 69.27001
## 2899 64.67498
## 2902 63.74487
## 2908 66.24860
## 2912 60.22454
## 2913 61.28320
## 2920 52.54212
## 2926 59.70816
## 2931 48.10812
## 2938 35.02091
MSPE = data.frame(Observed = validate$Life.expectancy,
Predicted = sw.select.model_Preds)
MSPE$Residual = MSPE$Observed - MSPE$Predicted
MSPE$SquaredResidual = MSPE$Residual^2
sqrt(mean(MSPE$SquaredResidual))
## [1] 4.521186
# RMSE of Original Model
original.model_Preds = predict(original.model, newdata = validate)
as.data.frame(original.model_Preds)
## original.model_Preds
## 1 62.00698
## 6 62.67364
## 7 62.04103
## 9 61.01874
## 10 60.33392
## 24 73.07173
## 28 71.69674
## 33 75.14697
## 35 75.12585
## 36 74.89521
## 42 71.83871
## 43 70.69296
## 48 68.97695
## 49 63.32559
## 57 60.86067
## 59 57.83462
## 60 54.72531
## 79 56.62073
## 80 56.36307
## 82 79.26422
## 105 69.32738
## 108 70.84764
## 115 87.02190
## 124 79.60654
## 129 80.29086
## 130 82.27297
## 136 78.69301
## 137 78.55665
## 151 71.00995
## 156 69.65243
## 157 69.24162
## 159 68.31973
## 164 75.02957
## 168 71.50002
## 174 73.61487
## 176 67.22297
## 182 72.51296
## 184 75.28874
## 186 75.11793
## 190 74.27687
## 193 66.74529
## 194 65.92339
## 201 63.72919
## 204 64.46545
## 206 63.10321
## 209 77.12707
## 210 77.30458
## 213 76.85851
## 218 75.22636
## 221 71.42882
## 223 73.72552
## 226 77.98855
## 232 76.90505
## 240 74.06419
## 242 81.49857
## 247 77.88112
## 258 70.74712
## 259 73.33693
## 264 72.74175
## 278 63.65791
## 285 60.82385
## 287 59.75891
## 288 59.67490
## 289 69.48890
## 296 62.15664
## 297 61.59028
## 298 61.10214
## 306 74.19989
## 307 73.76443
## 312 72.77488
## 318 71.73254
## 338 70.47342
## 339 69.61851
## 345 61.47979
## 351 42.26194
## 356 75.89389
## 368 74.28658
## 371 77.73112
## 375 75.62909
## 386 76.94642
## 402 63.03660
## 406 59.24801
## 409 59.47797
## 415 51.43880
## 418 66.16018
## 419 65.96848
## 426 59.26433
## 429 55.47894
## 430 54.96734
## 446 60.26261
## 448 63.03957
## 450 69.92309
## 451 71.26610
## 452 70.66296
## 453 64.12711
## 459 68.09309
## 460 67.98012
## 465 68.03554
## 468 66.33096
## 478 59.34773
## 480 58.53252
## 482 64.42847
## 492 58.22442
## 493 58.00162
## 503 79.03000
## 505 79.06670
## 509 76.73309
## 511 79.17828
## 513 56.59818
## 516 55.69656
## 518 53.00241
## 523 50.30745
## 527 44.82418
## 532 54.81944
## 537 53.35365
## 545 78.97759
## 555 76.27597
## 556 75.60251
## 559 75.25089
## 577 74.05325
## 580 74.11869
## 596 66.45840
## 601 63.70302
## 603 63.56949
## 614 63.23040
## 626 72.19975
## 627 75.34698
## 635 73.33795
## 642 77.60383
## 645 77.71974
## 646 77.64840
## 655 74.15987
## 658 75.40376
## 665 77.32856
## 673 72.48831
## 686 75.28485
## 698 74.02711
## 699 73.93498
## 701 70.78294
## 720 69.23909
## 729 66.77113
## 732 58.24646
## 751 81.07635
## 752 78.58716
## 758 61.79371
## 760 60.94184
## 767 55.28759
## 771 73.45352
## 774 72.81279
## 788 74.59469
## 798 69.74835
## 807 72.80599
## 816 71.12206
## 822 73.36111
## 823 70.54371
## 825 72.72513
## 835 58.18743
## 840 59.56793
## 847 59.72913
## 853 60.96616
## 858 60.47989
## 859 60.12506
## 864 51.62778
## 872 78.77644
## 876 78.33492
## 878 76.94945
## 881 75.65808
## 884 63.12480
## 894 52.04901
## 898 47.49345
## 899 76.54465
## 902 72.43819
## 904 75.14628
## 906 74.71222
## 911 73.03611
## 922 79.90315
## 925 81.81350
## 926 82.72348
## 931 80.95208
## 934 79.78115
## 935 76.39152
## 954 63.48762
## 958 57.66116
## 960 59.00861
## 961 59.55279
## 971 62.82329
## 978 57.28434
## 979 74.85484
## 988 72.93272
## 991 70.68529
## 994 61.34591
## 997 80.25853
## 1002 81.13120
## 1006 79.95248
## 1011 68.36062
## 1014 67.78846
## 1022 57.80672
## 1027 79.40251
## 1035 81.00013
## 1036 79.03603
## 1039 78.38359
## 1041 74.28005
## 1047 75.68321
## 1050 69.84834
## 1051 69.47264
## 1058 68.25827
## 1062 70.52581
## 1066 70.00426
## 1074 62.04208
## 1079 60.54241
## 1080 59.20801
## 1089 53.56951
## 1093 61.92047
## 1094 61.29241
## 1096 60.45159
## 1099 59.54511
## 1103 51.93469
## 1105 54.76906
## 1111 69.76305
## 1115 67.16384
## 1118 68.58458
## 1119 64.44764
## 1124 64.35269
## 1137 58.77744
## 1139 71.26721
## 1141 71.79178
## 1146 70.41165
## 1147 70.05968
## 1152 66.26764
## 1157 78.73082
## 1158 78.68335
## 1161 78.41505
## 1164 78.14078
## 1166 77.52438
## 1168 76.46770
## 1171 80.83328
## 1172 74.92378
## 1175 80.65517
## 1176 83.27755
## 1178 84.10627
## 1180 80.57073
## 1187 65.26239
## 1199 59.60539
## 1200 59.40860
## 1210 67.93497
## 1213 66.88398
## 1215 64.14436
## 1226 72.48492
## 1228 71.51328
## 1230 71.70809
## 1232 71.40156
## 1234 70.77814
## 1237 67.20760
## 1242 68.23066
## 1251 80.96626
## 1252 81.41713
## 1271 80.14510
## 1273 79.65601
## 1282 76.89036
## 1290 78.68794
## 1302 73.17200
## 1308 71.89758
## 1322 78.12525
## 1329 76.15226
## 1343 74.30129
## 1350 73.65343
## 1355 74.95323
## 1365 64.62586
## 1367 65.61515
## 1372 54.12985
## 1375 52.70721
## 1384 72.08973
## 1391 59.76826
## 1392 67.16878
## 1396 73.65295
## 1404 78.08830
## 1413 72.06450
## 1415 71.38023
## 1417 69.61030
## 1420 71.27814
## 1425 70.60545
## 1433 63.88228
## 1445 73.89123
## 1453 77.83218
## 1458 74.59759
## 1463 73.79569
## 1466 73.18560
## 1470 64.83459
## 1471 68.36791
## 1479 60.26027
## 1483 46.37921
## 1491 62.80027
## 1499 61.17040
## 1505 59.46977
## 1511 71.68163
## 1513 74.96231
## 1515 75.20717
## 1518 75.64009
## 1519 75.93251
## 1522 75.21329
## 1526 76.01955
## 1531 78.61639
## 1535 76.78166
## 1537 75.77070
## 1540 81.65976
## 1542 75.02397
## 1543 84.44153
## 1549 77.00459
## 1551 80.59527
## 1553 79.17191
## 1567 60.98553
## 1572 63.96892
## 1573 61.68849
## 1581 49.98473
## 1582 49.22669
## 1586 47.00396
## 1589 72.49778
## 1593 72.09956
## 1597 70.05520
## 1607 70.03394
## 1618 68.23438
## 1633 55.92212
## 1639 79.07717
## 1649 75.63389
## 1650 75.52986
## 1659 61.58676
## 1666 61.44180
## 1674 71.62724
## 1676 72.39705
## 1678 71.76407
## 1687 74.51804
## 1690 74.32530
## 1691 74.30124
## 1693 74.00040
## 1698 72.39987
## 1703 72.75810
## 1708 71.57485
## 1709 70.90545
## 1714 69.86434
## 1723 73.59189
## 1725 72.69905
## 1727 71.54454
## 1734 76.55115
## 1738 76.68279
## 1743 74.15915
## 1748 56.67950
## 1760 68.67657
## 1763 67.08688
## 1764 66.42792
## 1766 61.87903
## 1776 50.72184
## 1777 50.53964
## 1784 64.31384
## 1788 62.90410
## 1795 60.86747
## 1799 68.32213
## 1801 65.99840
## 1818 67.45512
## 1826 62.71954
## 1832 84.42236
## 1833 81.19742
## 1848 84.75491
## 1854 81.07325
## 1856 80.75675
## 1858 74.19981
## 1861 75.49495
## 1862 72.14986
## 1868 71.44897
## 1878 58.93552
## 1885 56.68745
## 1890 52.30504
## 1894 61.07872
## 1898 59.31498
## 1905 55.97627
## 1911 80.45326
## 1913 77.16611
## 1916 85.54940
## 1917 80.00915
## 1919 85.36086
## 1928 74.31598
## 1933 73.72274
## 1936 69.12432
## 1940 71.41308
## 1942 64.48676
## 1943 63.21535
## 1944 62.24038
## 1957 58.23353
## 1960 73.46141
## 1962 70.79455
## 1965 74.70036
## 1968 72.90302
## 1972 73.90409
## 1973 73.84304
## 1978 64.94776
## 1981 65.38777
## 1982 65.45515
## 1987 60.65942
## 1988 62.45371
## 1989 61.45878
## 1990 60.91968
## 1992 69.68002
## 1997 72.35398
## 2013 73.46183
## 2023 73.02123
## 2028 69.51749
## 2034 65.96916
## 2044 78.30558
## 2047 76.86773
## 2058 77.02650
## 2059 78.89916
## 2063 79.55187
## 2064 77.59509
## 2066 78.31857
## 2069 78.34685
## 2070 75.40932
## 2073 80.39058
## 2083 77.58678
## 2086 73.70943
## 2092 70.55977
## 2094 71.67523
## 2095 71.50345
## 2097 71.74265
## 2103 70.87108
## 2105 68.00587
## 2109 67.00593
## 2114 73.35422
## 2124 76.25302
## 2125 77.29316
## 2135 72.33390
## 2153 66.71137
## 2154 66.63085
## 2157 65.47834
## 2167 49.56909
## 2176 73.04762
## 2178 69.65931
## 2180 71.77441
## 2181 67.86098
## 2183 72.43997
## 2200 64.09343
## 2203 72.59486
## 2211 70.49735
## 2220 69.45293
## 2221 68.62917
## 2227 67.27196
## 2232 62.17336
## 2239 75.50896
## 2248 72.99520
## 2249 72.59211
## 2256 63.55549
## 2258 61.43924
## 2268 75.17276
## 2271 74.25136
## 2278 73.60003
## 2279 74.24690
## 2281 73.54382
## 2287 72.52554
## 2290 73.04537
## 2299 65.46322
## 2306 58.52594
## 2310 60.63357
## 2316 76.25897
## 2317 79.34218
## 2323 74.22101
## 2331 77.57450
## 2340 75.87857
## 2341 75.55959
## 2342 75.08224
## 2354 80.32487
## 2362 66.76351
## 2366 68.74074
## 2367 64.29951
## 2371 67.51558
## 2372 64.36003
## 2373 62.30194
## 2376 64.44992
## 2377 64.79079
## 2382 65.67007
## 2387 63.29378
## 2393 64.78769
## 2399 63.29519
## 2408 51.10100
## 2413 58.06241
## 2422 53.72636
## 2424 54.07227
## 2431 79.39532
## 2433 81.00464
## 2434 78.64550
## 2435 80.28871
## 2439 78.00684
## 2443 71.69799
## 2444 71.48657
## 2445 71.28770
## 2457 68.98362
## 2465 64.50656
## 2477 72.66274
## 2482 71.08572
## 2487 63.21845
## 2488 62.65637
## 2491 65.11867
## 2493 59.58466
## 2501 31.57448
## 2502 30.78894
## 2510 82.90883
## 2512 78.86479
## 2514 81.79250
## 2516 78.77811
## 2518 80.74302
## 2521 79.88235
## 2526 84.51901
## 2534 76.61283
## 2536 78.81157
## 2546 66.10262
## 2547 66.01227
## 2551 68.38156
## 2552 68.01105
## 2553 68.05605
## 2555 70.42264
## 2560 69.53851
## 2571 73.03411
## 2573 71.29481
## 2581 69.65656
## 2589 74.09906
## 2604 67.61153
## 2605 67.67830
## 2607 66.48297
## 2611 63.67531
## 2622 65.24407
## 2628 59.54491
## 2629 60.66651
## 2637 74.38234
## 2640 74.83279
## 2643 71.78534
## 2664 70.22870
## 2669 75.25153
## 2675 74.29640
## 2677 73.38349
## 2683 76.23673
## 2686 75.35111
## 2691 65.69767
## 2695 70.03019
## 2697 69.73279
## 2703 64.76257
## 2716 63.51091
## 2720 58.20465
## 2721 60.93522
## 2724 59.02288
## 2729 55.59369
## 2736 72.86659
## 2740 74.43540
## 2741 74.60038
## 2748 77.74878
## 2755 76.20913
## 2761 72.72649
## 2762 72.44000
## 2776 73.39712
## 2779 69.88780
## 2805 74.90730
## 2811 77.88440
## 2813 78.27957
## 2823 75.74780
## 2825 75.55056
## 2831 71.82741
## 2832 69.47918
## 2834 71.17256
## 2836 70.52318
## 2841 69.54837
## 2848 68.08558
## 2850 67.78178
## 2853 62.79227
## 2857 59.15016
## 2863 74.00885
## 2871 70.78678
## 2875 69.98561
## 2877 67.80600
## 2878 69.55786
## 2899 64.38566
## 2902 63.25688
## 2908 65.78477
## 2912 59.57095
## 2913 60.91770
## 2920 52.40302
## 2926 59.78845
## 2931 48.02131
## 2938 34.90615
MSPE = data.frame(Observed = validate$Life.expectancy,
Predicted = original.model_Preds)
MSPE$Residual = MSPE$Observed - MSPE$Predicted
MSPE$SquaredResidual = MSPE$Residual^2
sqrt(mean(MSPE$SquaredResidual))
## [1] 4.548685
# RMSE of Poly2Log Model
poly2logmodel_Preds = predict(poly2logmodel, newdata = validate)
as.data.frame(poly2logmodel_Preds)
## poly2logmodel_Preds
## 1 65.36285
## 6 65.04255
## 7 64.57153
## 9 64.07558
## 10 63.57594
## 24 75.15340
## 28 74.49068
## 33 75.77933
## 35 74.73490
## 36 74.68665
## 42 72.62916
## 43 69.86209
## 48 69.97629
## 49 59.53415
## 57 57.65260
## 59 56.91763
## 60 57.43848
## 79 68.29692
## 80 67.99165
## 82 80.00336
## 105 73.56737
## 108 72.97306
## 115 83.84505
## 124 82.45711
## 129 79.09504
## 130 79.48500
## 136 76.26041
## 137 76.27300
## 151 71.50479
## 156 69.37623
## 157 69.71964
## 159 68.41937
## 164 73.99311
## 168 74.78687
## 174 74.64601
## 176 68.77127
## 182 75.66910
## 184 75.74653
## 186 75.71337
## 190 75.01001
## 193 70.50388
## 194 68.94431
## 201 67.91196
## 204 68.89757
## 206 65.57496
## 209 77.69239
## 210 77.53767
## 213 77.11635
## 218 75.52773
## 221 70.60495
## 223 68.79800
## 226 76.74264
## 232 75.42076
## 240 74.11138
## 242 79.62985
## 247 79.08562
## 258 72.84780
## 259 73.15668
## 264 74.15598
## 278 58.90128
## 285 56.39172
## 287 56.08597
## 288 56.36596
## 289 68.23991
## 296 61.39419
## 297 61.92013
## 298 61.65784
## 306 75.85674
## 307 75.22626
## 312 72.02436
## 318 72.29254
## 338 63.23719
## 339 60.99163
## 345 58.61322
## 351 54.48637
## 356 76.81192
## 368 76.07938
## 371 76.59082
## 375 75.88854
## 386 75.94112
## 402 60.90420
## 406 61.19793
## 409 58.76365
## 415 50.79987
## 418 62.59232
## 419 61.56918
## 426 56.50613
## 429 53.79469
## 430 53.56022
## 446 56.55637
## 448 56.83985
## 450 70.34551
## 451 70.14270
## 452 67.95593
## 453 66.91956
## 459 65.02777
## 460 65.37016
## 465 69.55411
## 468 64.36302
## 478 55.18980
## 480 53.30017
## 482 57.65236
## 492 53.45678
## 493 54.07134
## 503 79.63121
## 505 80.67652
## 509 79.50925
## 511 79.46527
## 513 52.87530
## 516 51.10272
## 518 50.79731
## 523 48.85853
## 527 50.61146
## 532 54.66459
## 537 51.60181
## 545 79.66309
## 555 77.43983
## 556 76.60600
## 559 77.28857
## 577 74.58519
## 580 75.30146
## 596 62.03666
## 601 65.80368
## 603 65.66422
## 614 57.61624
## 626 75.39633
## 627 75.72007
## 635 74.71675
## 642 78.08990
## 645 77.58596
## 646 77.19050
## 655 73.69398
## 658 76.11105
## 665 77.99008
## 673 74.17941
## 686 76.81145
## 698 73.97012
## 699 74.01068
## 701 73.45732
## 720 69.55470
## 729 61.38720
## 732 58.19061
## 751 80.12571
## 752 78.68092
## 758 56.85955
## 760 57.19318
## 767 53.03872
## 771 70.71457
## 774 69.86324
## 788 75.20178
## 798 69.77258
## 807 73.10832
## 816 72.11862
## 822 71.13176
## 823 70.52063
## 825 70.65935
## 835 56.51264
## 840 54.89046
## 847 57.48048
## 853 62.63218
## 858 59.80014
## 859 59.15821
## 864 51.44088
## 872 76.49477
## 876 75.18618
## 878 74.69076
## 881 75.33519
## 884 61.30860
## 894 52.79707
## 898 49.74979
## 899 77.22721
## 902 74.81497
## 904 75.87496
## 906 75.53618
## 911 73.81689
## 922 80.56039
## 925 80.89492
## 926 82.00550
## 931 80.75524
## 934 79.96054
## 935 79.15860
## 954 57.08582
## 958 55.11058
## 960 54.28534
## 961 55.02049
## 971 58.99159
## 978 57.92349
## 979 75.97328
## 988 74.19307
## 991 71.41419
## 994 65.38296
## 997 79.95217
## 1002 79.80209
## 1006 79.15642
## 1011 65.26283
## 1014 63.36983
## 1022 55.66507
## 1027 79.46687
## 1035 80.78548
## 1036 79.69687
## 1039 78.79284
## 1041 77.51639
## 1047 76.46570
## 1050 71.63639
## 1051 71.04601
## 1058 70.23765
## 1062 69.14854
## 1066 68.63565
## 1074 67.40803
## 1079 55.24686
## 1080 54.88630
## 1089 55.01669
## 1093 54.74538
## 1094 54.25291
## 1096 55.32681
## 1099 54.17412
## 1103 50.30225
## 1105 51.00763
## 1111 68.55036
## 1115 63.86326
## 1118 62.46780
## 1119 60.57282
## 1124 60.01234
## 1137 54.18087
## 1139 70.50397
## 1141 69.67113
## 1146 67.31252
## 1147 66.75425
## 1152 63.58881
## 1157 78.75479
## 1158 78.60366
## 1161 78.34458
## 1164 77.36230
## 1166 76.51831
## 1168 75.60326
## 1171 81.23760
## 1172 79.75934
## 1175 79.96260
## 1176 82.33061
## 1178 82.51633
## 1180 81.51172
## 1187 67.39080
## 1199 61.08870
## 1200 60.87914
## 1210 66.83594
## 1213 67.88944
## 1215 67.44605
## 1226 73.04880
## 1228 72.36076
## 1230 72.62885
## 1232 72.38625
## 1234 72.03076
## 1237 68.90902
## 1242 68.63457
## 1251 82.16561
## 1252 82.07166
## 1271 79.19135
## 1273 79.18464
## 1282 77.30669
## 1290 79.35242
## 1302 69.84888
## 1308 66.56688
## 1322 79.22749
## 1329 78.17281
## 1343 74.21580
## 1350 77.62766
## 1355 76.50115
## 1365 59.37025
## 1367 60.04142
## 1372 52.81547
## 1375 50.82195
## 1384 73.67408
## 1391 65.54119
## 1392 66.96738
## 1396 74.57534
## 1404 76.26940
## 1413 72.80982
## 1415 71.50321
## 1417 73.15401
## 1420 72.81368
## 1425 73.23601
## 1433 65.83066
## 1445 76.54398
## 1453 78.45476
## 1458 76.03037
## 1463 73.36020
## 1466 72.39761
## 1470 66.95293
## 1471 67.66549
## 1479 56.91685
## 1483 51.88719
## 1491 59.45380
## 1499 54.83838
## 1505 54.93741
## 1511 73.56118
## 1513 74.51287
## 1515 74.71853
## 1518 74.75980
## 1519 75.28303
## 1522 74.74668
## 1526 75.84655
## 1531 77.18502
## 1535 76.13435
## 1537 75.48656
## 1540 78.88769
## 1542 78.20594
## 1543 79.30010
## 1549 77.77980
## 1551 77.97250
## 1553 77.67891
## 1567 58.66633
## 1572 56.83529
## 1573 55.23537
## 1581 50.75468
## 1582 50.88396
## 1586 49.27009
## 1589 73.59522
## 1593 73.62788
## 1597 73.14137
## 1607 72.82539
## 1618 71.75491
## 1633 53.07771
## 1639 79.40319
## 1649 77.00841
## 1650 76.78079
## 1659 57.94167
## 1666 58.65878
## 1674 75.35048
## 1676 74.86129
## 1678 74.54481
## 1687 76.16327
## 1690 76.05390
## 1691 76.16257
## 1693 76.15480
## 1698 74.52745
## 1703 73.96819
## 1708 72.78940
## 1709 71.62192
## 1714 71.79002
## 1723 75.24458
## 1725 74.41353
## 1727 73.82537
## 1734 75.70600
## 1738 77.61464
## 1743 75.31121
## 1748 65.88058
## 1760 70.78410
## 1763 69.87710
## 1764 69.40873
## 1766 55.36656
## 1776 50.88001
## 1777 50.86492
## 1784 62.72696
## 1788 61.41031
## 1795 60.19517
## 1799 60.99879
## 1801 58.13598
## 1818 67.40385
## 1826 65.61186
## 1832 82.57702
## 1833 82.07143
## 1848 83.43555
## 1854 81.54683
## 1856 81.28123
## 1858 79.07295
## 1861 78.42670
## 1862 73.79637
## 1868 71.70007
## 1878 60.64877
## 1885 55.37112
## 1890 52.61720
## 1894 56.04322
## 1898 54.88220
## 1905 52.81084
## 1911 81.41852
## 1913 80.24967
## 1916 81.95790
## 1917 80.46941
## 1919 82.01928
## 1928 74.68506
## 1933 74.47882
## 1936 72.65232
## 1940 73.20363
## 1942 66.47158
## 1943 67.57527
## 1944 65.80757
## 1957 62.92699
## 1960 73.85796
## 1962 74.17796
## 1965 76.22421
## 1968 71.78379
## 1972 76.16312
## 1973 74.03274
## 1978 61.71004
## 1981 60.33010
## 1982 60.57749
## 1987 57.82872
## 1988 58.33144
## 1989 57.61545
## 1990 57.60556
## 1992 71.35454
## 1997 74.19150
## 2013 72.85783
## 2023 70.83928
## 2028 73.24052
## 2034 72.99517
## 2044 78.58750
## 2047 76.37051
## 2058 79.80083
## 2059 78.84506
## 2063 78.79821
## 2064 77.53272
## 2066 77.26810
## 2069 78.62387
## 2070 77.86107
## 2073 75.40782
## 2083 76.11660
## 2086 73.88888
## 2092 75.12233
## 2094 74.46614
## 2095 74.39979
## 2097 75.03093
## 2103 73.99501
## 2105 71.19793
## 2109 71.81766
## 2114 74.54117
## 2124 75.37228
## 2125 77.74724
## 2135 74.30055
## 2153 65.14648
## 2154 65.20816
## 2157 61.49394
## 2167 51.85972
## 2176 73.81467
## 2178 71.25844
## 2180 70.57970
## 2181 68.14025
## 2183 70.55800
## 2200 63.11184
## 2203 72.60637
## 2211 72.32554
## 2220 69.03982
## 2221 64.98852
## 2227 64.14739
## 2232 60.79124
## 2239 74.99567
## 2248 73.46745
## 2249 73.03622
## 2256 61.67465
## 2258 60.95151
## 2268 76.43792
## 2271 75.36668
## 2278 74.72811
## 2279 75.60905
## 2281 74.06250
## 2287 74.55079
## 2290 75.81230
## 2299 61.08206
## 2306 55.69103
## 2310 56.93909
## 2316 77.80976
## 2317 78.58515
## 2323 76.38819
## 2331 77.94135
## 2340 76.85232
## 2341 76.87114
## 2342 76.64147
## 2354 79.72118
## 2362 72.64387
## 2366 71.80706
## 2367 68.38340
## 2371 71.08510
## 2372 68.77401
## 2373 67.51534
## 2376 68.19068
## 2377 67.88946
## 2382 61.34600
## 2387 61.38671
## 2393 61.47270
## 2399 57.18471
## 2408 53.86808
## 2413 54.93225
## 2422 56.04085
## 2424 56.51490
## 2431 79.98573
## 2433 80.34702
## 2434 78.98351
## 2435 79.63864
## 2439 78.14410
## 2443 73.94768
## 2444 73.85914
## 2445 73.80544
## 2457 72.22228
## 2465 65.34800
## 2477 67.33926
## 2482 66.65024
## 2487 57.35935
## 2488 56.50260
## 2491 58.57560
## 2493 56.33145
## 2501 50.89404
## 2502 48.95950
## 2510 80.99026
## 2512 79.86687
## 2514 80.63407
## 2516 79.87535
## 2518 80.62376
## 2521 80.31691
## 2526 81.00702
## 2534 77.86487
## 2536 78.46888
## 2546 68.63360
## 2547 69.25685
## 2551 69.65846
## 2552 69.34732
## 2553 69.53944
## 2555 68.94708
## 2560 68.74060
## 2571 75.79362
## 2573 75.62126
## 2581 68.83205
## 2589 74.45050
## 2604 68.41235
## 2605 69.28158
## 2607 67.90513
## 2611 65.65429
## 2622 58.75733
## 2628 55.25533
## 2629 54.05078
## 2637 73.86940
## 2640 74.18828
## 2643 75.90395
## 2664 65.92786
## 2669 75.21351
## 2675 74.90331
## 2677 74.03319
## 2683 75.94349
## 2686 75.48790
## 2691 70.04140
## 2695 69.86840
## 2697 70.92398
## 2703 67.89668
## 2716 56.62387
## 2720 55.11144
## 2721 55.49390
## 2724 53.47347
## 2729 51.01863
## 2736 70.80682
## 2740 69.07944
## 2741 69.47736
## 2748 76.75885
## 2755 75.18894
## 2761 73.89355
## 2762 73.72997
## 2776 74.28485
## 2779 65.77646
## 2805 76.27514
## 2811 78.24547
## 2813 78.56469
## 2823 76.58712
## 2825 76.80081
## 2831 74.11609
## 2832 71.62497
## 2834 69.45426
## 2836 68.33655
## 2841 69.85779
## 2848 69.18885
## 2850 69.23409
## 2853 64.38059
## 2857 64.54653
## 2863 74.45297
## 2871 71.56684
## 2875 73.38086
## 2877 69.24940
## 2878 73.20412
## 2899 66.70666
## 2902 65.71903
## 2908 58.51361
## 2912 56.73322
## 2913 57.18364
## 2920 51.85048
## 2926 57.16869
## 2931 50.23588
## 2938 48.44372
MSPE = data.frame(Observed = validate$Life.expectancy,
Predicted = poly2logmodel_Preds)
MSPE$Residual = MSPE$Observed - MSPE$Predicted
MSPE$SquaredResidual = MSPE$Residual^2
sqrt(mean(MSPE$SquaredResidual))
## [1] 3.80083
# RMSE of Poly7Log Model
poly7logmodel_Preds = predict(poly7logmodel, newdata = validate)
as.data.frame(poly7logmodel_Preds)
## poly7logmodel_Preds
## 1 64.55388
## 6 64.63545
## 7 64.04218
## 9 63.61055
## 10 62.72954
## 24 73.89513
## 28 73.73148
## 33 75.42495
## 35 74.68598
## 36 74.53141
## 42 73.02623
## 43 70.81147
## 48 71.26674
## 49 59.46023
## 57 56.36704
## 59 52.21586
## 60 51.49338
## 79 68.47678
## 80 68.87456
## 82 80.45484
## 105 74.73570
## 108 73.30255
## 115 82.69919
## 124 79.75191
## 129 78.61779
## 130 79.29858
## 136 76.87916
## 137 77.13504
## 151 72.13667
## 156 70.41583
## 157 70.86806
## 159 69.80782
## 164 74.11020
## 168 76.10504
## 174 75.40978
## 176 69.40519
## 182 75.40450
## 184 75.39451
## 186 74.90823
## 190 74.23880
## 193 69.15356
## 194 68.39626
## 201 67.77178
## 204 68.41493
## 206 66.07673
## 209 76.32959
## 210 76.65380
## 213 76.34102
## 218 74.99832
## 221 71.38613
## 223 69.49880
## 226 78.54082
## 232 77.00249
## 240 74.41756
## 242 80.63174
## 247 79.17335
## 258 73.37997
## 259 72.52622
## 264 73.95395
## 278 59.06657
## 285 55.71715
## 287 55.35327
## 288 55.63391
## 289 67.03252
## 296 60.97127
## 297 61.60121
## 298 61.22671
## 306 74.22900
## 307 74.48858
## 312 71.56868
## 318 72.29443
## 338 64.56090
## 339 62.46182
## 345 59.31577
## 351 55.13333
## 356 75.65736
## 368 74.65417
## 371 76.26902
## 375 75.82988
## 386 77.50731
## 402 60.48274
## 406 60.60787
## 409 58.60955
## 415 52.54928
## 418 62.40158
## 419 61.23364
## 426 54.98851
## 429 53.76503
## 430 53.99025
## 446 57.47623
## 448 56.32813
## 450 71.24536
## 451 70.87027
## 452 68.72279
## 453 69.44132
## 459 64.77008
## 460 65.15527
## 465 68.79294
## 468 64.28664
## 478 54.31858
## 480 53.04936
## 482 59.12161
## 492 52.99388
## 493 53.45062
## 503 79.75054
## 505 81.33397
## 509 79.42781
## 511 78.98539
## 513 49.86176
## 516 48.72663
## 518 48.85145
## 523 46.47901
## 527 45.72261
## 532 52.23259
## 537 49.79181
## 545 79.72329
## 555 77.10782
## 556 76.07398
## 559 76.21249
## 577 74.58652
## 580 74.95830
## 596 62.36886
## 601 66.78862
## 603 65.74297
## 614 58.05413
## 626 75.85706
## 627 75.71371
## 635 74.36624
## 642 78.27145
## 645 78.30324
## 646 78.14842
## 655 75.36409
## 658 75.34953
## 665 77.03063
## 673 73.41894
## 686 76.40491
## 698 75.65204
## 699 75.70665
## 701 75.62612
## 720 69.18999
## 729 61.31893
## 732 59.08432
## 751 79.45549
## 752 78.29033
## 758 58.03509
## 760 58.55782
## 767 56.34725
## 771 71.17136
## 774 69.73765
## 788 74.49026
## 798 71.03658
## 807 73.71595
## 816 72.28700
## 822 71.12168
## 823 71.54376
## 825 70.65821
## 835 58.50745
## 840 54.15841
## 847 55.11803
## 853 62.52961
## 858 59.79800
## 859 59.17147
## 864 54.44041
## 872 78.86812
## 876 78.45861
## 878 76.91375
## 881 75.20976
## 884 61.17699
## 894 51.37127
## 898 49.14349
## 899 76.34892
## 902 74.79517
## 904 74.88658
## 906 74.50911
## 911 73.71766
## 922 80.50833
## 925 80.61339
## 926 81.95533
## 931 80.26982
## 934 79.79446
## 935 79.47713
## 954 58.42096
## 958 53.54413
## 960 52.47652
## 961 53.32122
## 971 58.27864
## 978 57.62422
## 979 75.32607
## 988 73.89785
## 991 71.45069
## 994 65.98876
## 997 80.68283
## 1002 80.56844
## 1006 79.76164
## 1011 65.89747
## 1014 64.39744
## 1022 55.70325
## 1027 79.16895
## 1035 80.17428
## 1036 79.28116
## 1039 78.63198
## 1041 78.13320
## 1047 75.79333
## 1050 70.39576
## 1051 70.58655
## 1058 70.06512
## 1062 69.38456
## 1066 69.00665
## 1074 69.66400
## 1079 55.21619
## 1080 56.25599
## 1089 54.36796
## 1093 55.55390
## 1094 54.97881
## 1096 54.98280
## 1099 53.63370
## 1103 49.37665
## 1105 49.29678
## 1111 69.04243
## 1115 65.00106
## 1118 63.76382
## 1119 63.54056
## 1124 59.64422
## 1137 53.50966
## 1139 70.05630
## 1141 69.18265
## 1146 67.77864
## 1147 67.25856
## 1152 64.75707
## 1157 78.65213
## 1158 78.59295
## 1161 78.20049
## 1164 77.74330
## 1166 76.84320
## 1168 76.16736
## 1171 81.71577
## 1172 82.71695
## 1175 80.17564
## 1176 82.17439
## 1178 81.87282
## 1180 80.87748
## 1187 67.38694
## 1199 61.51378
## 1200 61.09330
## 1210 67.48505
## 1213 68.05064
## 1215 69.08818
## 1226 72.48394
## 1228 72.02185
## 1230 72.50685
## 1232 72.22637
## 1234 72.10426
## 1237 70.46529
## 1242 69.46014
## 1251 82.79934
## 1252 83.12381
## 1271 79.46403
## 1273 79.13481
## 1282 77.12804
## 1290 78.98565
## 1302 69.38669
## 1308 66.03500
## 1322 77.42955
## 1329 75.76464
## 1343 73.98742
## 1350 77.08429
## 1355 75.88588
## 1365 61.23604
## 1367 59.56115
## 1372 53.18431
## 1375 50.54953
## 1384 69.76718
## 1391 66.79103
## 1392 68.75813
## 1396 75.60098
## 1404 76.38450
## 1413 73.18587
## 1415 71.85375
## 1417 73.88723
## 1420 73.68057
## 1425 73.24581
## 1433 64.93813
## 1445 77.35747
## 1453 77.32605
## 1458 75.14067
## 1463 74.35198
## 1466 73.27406
## 1470 67.45238
## 1471 67.55541
## 1479 57.79741
## 1483 52.82901
## 1491 58.64953
## 1499 54.81282
## 1505 54.71435
## 1511 73.92437
## 1513 74.35615
## 1515 74.32855
## 1518 74.41979
## 1519 75.08966
## 1522 74.56037
## 1526 79.09298
## 1531 78.71249
## 1535 76.45027
## 1537 75.22929
## 1540 78.96682
## 1542 78.51249
## 1543 79.66123
## 1549 77.57930
## 1551 77.96556
## 1553 77.74372
## 1567 59.19826
## 1572 56.58998
## 1573 55.86759
## 1581 51.00974
## 1582 51.59518
## 1586 49.95097
## 1589 74.28251
## 1593 74.42089
## 1597 74.12798
## 1607 72.09948
## 1618 70.51460
## 1633 52.76605
## 1639 78.78208
## 1649 77.14765
## 1650 76.96212
## 1659 58.30494
## 1666 58.34048
## 1674 74.56776
## 1676 74.41961
## 1678 73.88261
## 1687 75.62485
## 1690 76.05292
## 1691 75.96177
## 1693 75.41371
## 1698 73.91166
## 1703 74.74411
## 1708 74.17788
## 1709 72.51461
## 1714 72.80204
## 1723 74.54476
## 1725 73.68211
## 1727 73.46771
## 1734 76.49781
## 1738 77.07299
## 1743 75.02015
## 1748 66.80643
## 1760 70.92936
## 1763 70.17346
## 1764 69.78079
## 1766 55.58541
## 1776 50.61119
## 1777 50.75469
## 1784 63.15899
## 1788 61.20300
## 1795 59.95413
## 1799 62.77078
## 1801 59.45621
## 1818 67.27385
## 1826 65.96814
## 1832 82.49201
## 1833 82.28968
## 1848 83.91822
## 1854 82.38192
## 1856 82.25161
## 1858 81.25552
## 1861 79.60954
## 1862 72.84998
## 1868 70.79369
## 1878 59.69363
## 1885 56.50435
## 1890 53.45345
## 1894 54.60068
## 1898 53.14073
## 1905 51.11173
## 1911 81.64296
## 1913 80.64420
## 1916 81.76426
## 1917 80.27417
## 1919 81.73070
## 1928 73.84989
## 1933 74.47364
## 1936 73.80763
## 1940 73.02916
## 1942 66.41513
## 1943 66.90658
## 1944 65.80882
## 1957 62.42586
## 1960 73.95283
## 1962 74.18736
## 1965 75.60071
## 1968 71.33033
## 1972 75.21473
## 1973 72.60308
## 1978 64.28664
## 1981 61.17774
## 1982 61.59453
## 1987 59.16360
## 1988 59.86541
## 1989 58.49395
## 1990 57.64666
## 1992 72.13434
## 1997 73.56926
## 2013 72.36938
## 2023 70.29383
## 2028 72.92075
## 2034 74.31516
## 2044 78.51938
## 2047 76.36893
## 2058 79.71069
## 2059 79.07012
## 2063 78.88595
## 2064 77.81097
## 2066 78.14771
## 2069 78.36820
## 2070 78.91584
## 2073 76.05812
## 2083 77.01755
## 2086 75.48049
## 2092 75.08168
## 2094 74.80244
## 2095 74.72315
## 2097 74.52518
## 2103 73.64836
## 2105 73.53675
## 2109 74.23780
## 2114 73.98495
## 2124 75.46036
## 2125 77.33286
## 2135 73.78829
## 2153 65.80740
## 2154 65.41298
## 2157 60.49330
## 2167 53.74004
## 2176 74.95398
## 2178 74.10207
## 2180 72.53214
## 2181 72.07491
## 2183 71.45520
## 2200 62.95632
## 2203 70.35044
## 2211 71.47276
## 2220 69.53460
## 2221 65.78864
## 2227 63.28627
## 2232 61.16937
## 2239 75.65243
## 2248 73.83756
## 2249 73.71125
## 2256 61.22378
## 2258 61.35198
## 2268 76.40085
## 2271 75.76277
## 2278 74.25959
## 2279 74.69493
## 2281 73.10998
## 2287 73.93637
## 2290 75.11349
## 2299 61.27407
## 2306 56.04692
## 2310 55.96224
## 2316 77.65659
## 2317 78.34173
## 2323 76.88612
## 2331 77.65654
## 2340 75.84577
## 2341 75.64950
## 2342 75.71192
## 2354 79.39818
## 2362 72.69885
## 2366 71.32502
## 2367 70.79478
## 2371 70.65034
## 2372 70.57002
## 2373 69.78310
## 2376 69.31183
## 2377 69.07522
## 2382 60.22460
## 2387 60.16276
## 2393 58.33583
## 2399 57.35827
## 2408 54.99102
## 2413 55.40366
## 2422 57.17511
## 2424 57.63359
## 2431 80.15480
## 2433 80.44934
## 2434 79.55900
## 2435 79.97598
## 2439 78.45121
## 2443 72.10288
## 2444 71.92679
## 2445 71.78387
## 2457 71.12198
## 2465 65.33164
## 2477 67.30393
## 2482 66.68621
## 2487 57.44975
## 2488 56.97615
## 2491 59.44921
## 2493 57.99697
## 2501 51.64863
## 2502 49.71687
## 2510 79.44654
## 2512 78.35070
## 2514 78.96855
## 2516 78.17836
## 2518 78.53262
## 2521 78.16587
## 2526 80.20859
## 2534 77.99369
## 2536 78.65321
## 2546 69.88633
## 2547 70.47008
## 2551 70.70345
## 2552 70.27874
## 2553 70.64480
## 2555 70.14597
## 2560 70.46214
## 2571 74.84791
## 2573 74.64625
## 2581 67.48463
## 2589 74.71491
## 2604 68.35087
## 2605 69.20243
## 2607 67.98273
## 2611 66.21197
## 2622 59.02596
## 2628 56.72897
## 2629 54.22458
## 2637 70.95952
## 2640 73.18066
## 2643 76.81953
## 2664 66.98731
## 2669 74.75214
## 2675 73.55875
## 2677 73.34678
## 2683 76.40791
## 2686 75.79071
## 2691 73.52544
## 2695 70.52959
## 2697 71.61571
## 2703 68.27533
## 2716 56.85926
## 2720 55.39658
## 2721 55.46634
## 2724 53.79690
## 2729 51.57261
## 2736 69.75599
## 2740 68.25437
## 2741 68.82526
## 2748 76.60273
## 2755 75.52542
## 2761 74.33838
## 2762 74.16046
## 2776 75.69274
## 2779 64.99686
## 2805 76.60897
## 2811 78.32349
## 2813 78.39176
## 2823 76.00323
## 2825 75.95617
## 2831 73.75896
## 2832 71.86211
## 2834 69.80728
## 2836 69.37073
## 2841 70.30206
## 2848 69.86345
## 2850 70.18138
## 2853 65.55920
## 2857 66.20383
## 2863 74.39547
## 2871 71.60304
## 2875 71.71012
## 2877 67.90915
## 2878 71.68078
## 2899 67.90733
## 2902 66.97416
## 2908 58.49287
## 2912 59.32643
## 2913 58.02214
## 2920 52.07851
## 2926 57.94492
## 2931 51.05890
## 2938 49.20722
MSPE = data.frame(Observed = validate$Life.expectancy, Predicted = poly7logmodel_Preds)
MSPE$Residual = MSPE$Observed - MSPE$Predicted
MSPE$SquaredResidual = MSPE$Residual^2
sqrt(mean(MSPE$SquaredResidual))
## [1] 3.734417
# RMSE of Original with Interaction Model
interaction.model_Preds = predict(interaction.model, newdata = validate)
as.data.frame(original.model_Preds)
## original.model_Preds
## 1 62.00698
## 6 62.67364
## 7 62.04103
## 9 61.01874
## 10 60.33392
## 24 73.07173
## 28 71.69674
## 33 75.14697
## 35 75.12585
## 36 74.89521
## 42 71.83871
## 43 70.69296
## 48 68.97695
## 49 63.32559
## 57 60.86067
## 59 57.83462
## 60 54.72531
## 79 56.62073
## 80 56.36307
## 82 79.26422
## 105 69.32738
## 108 70.84764
## 115 87.02190
## 124 79.60654
## 129 80.29086
## 130 82.27297
## 136 78.69301
## 137 78.55665
## 151 71.00995
## 156 69.65243
## 157 69.24162
## 159 68.31973
## 164 75.02957
## 168 71.50002
## 174 73.61487
## 176 67.22297
## 182 72.51296
## 184 75.28874
## 186 75.11793
## 190 74.27687
## 193 66.74529
## 194 65.92339
## 201 63.72919
## 204 64.46545
## 206 63.10321
## 209 77.12707
## 210 77.30458
## 213 76.85851
## 218 75.22636
## 221 71.42882
## 223 73.72552
## 226 77.98855
## 232 76.90505
## 240 74.06419
## 242 81.49857
## 247 77.88112
## 258 70.74712
## 259 73.33693
## 264 72.74175
## 278 63.65791
## 285 60.82385
## 287 59.75891
## 288 59.67490
## 289 69.48890
## 296 62.15664
## 297 61.59028
## 298 61.10214
## 306 74.19989
## 307 73.76443
## 312 72.77488
## 318 71.73254
## 338 70.47342
## 339 69.61851
## 345 61.47979
## 351 42.26194
## 356 75.89389
## 368 74.28658
## 371 77.73112
## 375 75.62909
## 386 76.94642
## 402 63.03660
## 406 59.24801
## 409 59.47797
## 415 51.43880
## 418 66.16018
## 419 65.96848
## 426 59.26433
## 429 55.47894
## 430 54.96734
## 446 60.26261
## 448 63.03957
## 450 69.92309
## 451 71.26610
## 452 70.66296
## 453 64.12711
## 459 68.09309
## 460 67.98012
## 465 68.03554
## 468 66.33096
## 478 59.34773
## 480 58.53252
## 482 64.42847
## 492 58.22442
## 493 58.00162
## 503 79.03000
## 505 79.06670
## 509 76.73309
## 511 79.17828
## 513 56.59818
## 516 55.69656
## 518 53.00241
## 523 50.30745
## 527 44.82418
## 532 54.81944
## 537 53.35365
## 545 78.97759
## 555 76.27597
## 556 75.60251
## 559 75.25089
## 577 74.05325
## 580 74.11869
## 596 66.45840
## 601 63.70302
## 603 63.56949
## 614 63.23040
## 626 72.19975
## 627 75.34698
## 635 73.33795
## 642 77.60383
## 645 77.71974
## 646 77.64840
## 655 74.15987
## 658 75.40376
## 665 77.32856
## 673 72.48831
## 686 75.28485
## 698 74.02711
## 699 73.93498
## 701 70.78294
## 720 69.23909
## 729 66.77113
## 732 58.24646
## 751 81.07635
## 752 78.58716
## 758 61.79371
## 760 60.94184
## 767 55.28759
## 771 73.45352
## 774 72.81279
## 788 74.59469
## 798 69.74835
## 807 72.80599
## 816 71.12206
## 822 73.36111
## 823 70.54371
## 825 72.72513
## 835 58.18743
## 840 59.56793
## 847 59.72913
## 853 60.96616
## 858 60.47989
## 859 60.12506
## 864 51.62778
## 872 78.77644
## 876 78.33492
## 878 76.94945
## 881 75.65808
## 884 63.12480
## 894 52.04901
## 898 47.49345
## 899 76.54465
## 902 72.43819
## 904 75.14628
## 906 74.71222
## 911 73.03611
## 922 79.90315
## 925 81.81350
## 926 82.72348
## 931 80.95208
## 934 79.78115
## 935 76.39152
## 954 63.48762
## 958 57.66116
## 960 59.00861
## 961 59.55279
## 971 62.82329
## 978 57.28434
## 979 74.85484
## 988 72.93272
## 991 70.68529
## 994 61.34591
## 997 80.25853
## 1002 81.13120
## 1006 79.95248
## 1011 68.36062
## 1014 67.78846
## 1022 57.80672
## 1027 79.40251
## 1035 81.00013
## 1036 79.03603
## 1039 78.38359
## 1041 74.28005
## 1047 75.68321
## 1050 69.84834
## 1051 69.47264
## 1058 68.25827
## 1062 70.52581
## 1066 70.00426
## 1074 62.04208
## 1079 60.54241
## 1080 59.20801
## 1089 53.56951
## 1093 61.92047
## 1094 61.29241
## 1096 60.45159
## 1099 59.54511
## 1103 51.93469
## 1105 54.76906
## 1111 69.76305
## 1115 67.16384
## 1118 68.58458
## 1119 64.44764
## 1124 64.35269
## 1137 58.77744
## 1139 71.26721
## 1141 71.79178
## 1146 70.41165
## 1147 70.05968
## 1152 66.26764
## 1157 78.73082
## 1158 78.68335
## 1161 78.41505
## 1164 78.14078
## 1166 77.52438
## 1168 76.46770
## 1171 80.83328
## 1172 74.92378
## 1175 80.65517
## 1176 83.27755
## 1178 84.10627
## 1180 80.57073
## 1187 65.26239
## 1199 59.60539
## 1200 59.40860
## 1210 67.93497
## 1213 66.88398
## 1215 64.14436
## 1226 72.48492
## 1228 71.51328
## 1230 71.70809
## 1232 71.40156
## 1234 70.77814
## 1237 67.20760
## 1242 68.23066
## 1251 80.96626
## 1252 81.41713
## 1271 80.14510
## 1273 79.65601
## 1282 76.89036
## 1290 78.68794
## 1302 73.17200
## 1308 71.89758
## 1322 78.12525
## 1329 76.15226
## 1343 74.30129
## 1350 73.65343
## 1355 74.95323
## 1365 64.62586
## 1367 65.61515
## 1372 54.12985
## 1375 52.70721
## 1384 72.08973
## 1391 59.76826
## 1392 67.16878
## 1396 73.65295
## 1404 78.08830
## 1413 72.06450
## 1415 71.38023
## 1417 69.61030
## 1420 71.27814
## 1425 70.60545
## 1433 63.88228
## 1445 73.89123
## 1453 77.83218
## 1458 74.59759
## 1463 73.79569
## 1466 73.18560
## 1470 64.83459
## 1471 68.36791
## 1479 60.26027
## 1483 46.37921
## 1491 62.80027
## 1499 61.17040
## 1505 59.46977
## 1511 71.68163
## 1513 74.96231
## 1515 75.20717
## 1518 75.64009
## 1519 75.93251
## 1522 75.21329
## 1526 76.01955
## 1531 78.61639
## 1535 76.78166
## 1537 75.77070
## 1540 81.65976
## 1542 75.02397
## 1543 84.44153
## 1549 77.00459
## 1551 80.59527
## 1553 79.17191
## 1567 60.98553
## 1572 63.96892
## 1573 61.68849
## 1581 49.98473
## 1582 49.22669
## 1586 47.00396
## 1589 72.49778
## 1593 72.09956
## 1597 70.05520
## 1607 70.03394
## 1618 68.23438
## 1633 55.92212
## 1639 79.07717
## 1649 75.63389
## 1650 75.52986
## 1659 61.58676
## 1666 61.44180
## 1674 71.62724
## 1676 72.39705
## 1678 71.76407
## 1687 74.51804
## 1690 74.32530
## 1691 74.30124
## 1693 74.00040
## 1698 72.39987
## 1703 72.75810
## 1708 71.57485
## 1709 70.90545
## 1714 69.86434
## 1723 73.59189
## 1725 72.69905
## 1727 71.54454
## 1734 76.55115
## 1738 76.68279
## 1743 74.15915
## 1748 56.67950
## 1760 68.67657
## 1763 67.08688
## 1764 66.42792
## 1766 61.87903
## 1776 50.72184
## 1777 50.53964
## 1784 64.31384
## 1788 62.90410
## 1795 60.86747
## 1799 68.32213
## 1801 65.99840
## 1818 67.45512
## 1826 62.71954
## 1832 84.42236
## 1833 81.19742
## 1848 84.75491
## 1854 81.07325
## 1856 80.75675
## 1858 74.19981
## 1861 75.49495
## 1862 72.14986
## 1868 71.44897
## 1878 58.93552
## 1885 56.68745
## 1890 52.30504
## 1894 61.07872
## 1898 59.31498
## 1905 55.97627
## 1911 80.45326
## 1913 77.16611
## 1916 85.54940
## 1917 80.00915
## 1919 85.36086
## 1928 74.31598
## 1933 73.72274
## 1936 69.12432
## 1940 71.41308
## 1942 64.48676
## 1943 63.21535
## 1944 62.24038
## 1957 58.23353
## 1960 73.46141
## 1962 70.79455
## 1965 74.70036
## 1968 72.90302
## 1972 73.90409
## 1973 73.84304
## 1978 64.94776
## 1981 65.38777
## 1982 65.45515
## 1987 60.65942
## 1988 62.45371
## 1989 61.45878
## 1990 60.91968
## 1992 69.68002
## 1997 72.35398
## 2013 73.46183
## 2023 73.02123
## 2028 69.51749
## 2034 65.96916
## 2044 78.30558
## 2047 76.86773
## 2058 77.02650
## 2059 78.89916
## 2063 79.55187
## 2064 77.59509
## 2066 78.31857
## 2069 78.34685
## 2070 75.40932
## 2073 80.39058
## 2083 77.58678
## 2086 73.70943
## 2092 70.55977
## 2094 71.67523
## 2095 71.50345
## 2097 71.74265
## 2103 70.87108
## 2105 68.00587
## 2109 67.00593
## 2114 73.35422
## 2124 76.25302
## 2125 77.29316
## 2135 72.33390
## 2153 66.71137
## 2154 66.63085
## 2157 65.47834
## 2167 49.56909
## 2176 73.04762
## 2178 69.65931
## 2180 71.77441
## 2181 67.86098
## 2183 72.43997
## 2200 64.09343
## 2203 72.59486
## 2211 70.49735
## 2220 69.45293
## 2221 68.62917
## 2227 67.27196
## 2232 62.17336
## 2239 75.50896
## 2248 72.99520
## 2249 72.59211
## 2256 63.55549
## 2258 61.43924
## 2268 75.17276
## 2271 74.25136
## 2278 73.60003
## 2279 74.24690
## 2281 73.54382
## 2287 72.52554
## 2290 73.04537
## 2299 65.46322
## 2306 58.52594
## 2310 60.63357
## 2316 76.25897
## 2317 79.34218
## 2323 74.22101
## 2331 77.57450
## 2340 75.87857
## 2341 75.55959
## 2342 75.08224
## 2354 80.32487
## 2362 66.76351
## 2366 68.74074
## 2367 64.29951
## 2371 67.51558
## 2372 64.36003
## 2373 62.30194
## 2376 64.44992
## 2377 64.79079
## 2382 65.67007
## 2387 63.29378
## 2393 64.78769
## 2399 63.29519
## 2408 51.10100
## 2413 58.06241
## 2422 53.72636
## 2424 54.07227
## 2431 79.39532
## 2433 81.00464
## 2434 78.64550
## 2435 80.28871
## 2439 78.00684
## 2443 71.69799
## 2444 71.48657
## 2445 71.28770
## 2457 68.98362
## 2465 64.50656
## 2477 72.66274
## 2482 71.08572
## 2487 63.21845
## 2488 62.65637
## 2491 65.11867
## 2493 59.58466
## 2501 31.57448
## 2502 30.78894
## 2510 82.90883
## 2512 78.86479
## 2514 81.79250
## 2516 78.77811
## 2518 80.74302
## 2521 79.88235
## 2526 84.51901
## 2534 76.61283
## 2536 78.81157
## 2546 66.10262
## 2547 66.01227
## 2551 68.38156
## 2552 68.01105
## 2553 68.05605
## 2555 70.42264
## 2560 69.53851
## 2571 73.03411
## 2573 71.29481
## 2581 69.65656
## 2589 74.09906
## 2604 67.61153
## 2605 67.67830
## 2607 66.48297
## 2611 63.67531
## 2622 65.24407
## 2628 59.54491
## 2629 60.66651
## 2637 74.38234
## 2640 74.83279
## 2643 71.78534
## 2664 70.22870
## 2669 75.25153
## 2675 74.29640
## 2677 73.38349
## 2683 76.23673
## 2686 75.35111
## 2691 65.69767
## 2695 70.03019
## 2697 69.73279
## 2703 64.76257
## 2716 63.51091
## 2720 58.20465
## 2721 60.93522
## 2724 59.02288
## 2729 55.59369
## 2736 72.86659
## 2740 74.43540
## 2741 74.60038
## 2748 77.74878
## 2755 76.20913
## 2761 72.72649
## 2762 72.44000
## 2776 73.39712
## 2779 69.88780
## 2805 74.90730
## 2811 77.88440
## 2813 78.27957
## 2823 75.74780
## 2825 75.55056
## 2831 71.82741
## 2832 69.47918
## 2834 71.17256
## 2836 70.52318
## 2841 69.54837
## 2848 68.08558
## 2850 67.78178
## 2853 62.79227
## 2857 59.15016
## 2863 74.00885
## 2871 70.78678
## 2875 69.98561
## 2877 67.80600
## 2878 69.55786
## 2899 64.38566
## 2902 63.25688
## 2908 65.78477
## 2912 59.57095
## 2913 60.91770
## 2920 52.40302
## 2926 59.78845
## 2931 48.02131
## 2938 34.90615
MSPE = data.frame(Observed = validate$Life.expectancy,
Predicted = interaction.model_Preds)
MSPE$Residual = MSPE$Observed - MSPE$Predicted
MSPE$SquaredResidual = MSPE$Residual^2
sqrt(mean(MSPE$SquaredResidual))
## [1] 4.369254
# RMSE of Poly2Log Model with interactions
poly2log.interaction.model_Preds = predict(poly2log.interaction.model, newdata = validate)
as.data.frame(poly2logmodel_Preds)
## poly2logmodel_Preds
## 1 65.36285
## 6 65.04255
## 7 64.57153
## 9 64.07558
## 10 63.57594
## 24 75.15340
## 28 74.49068
## 33 75.77933
## 35 74.73490
## 36 74.68665
## 42 72.62916
## 43 69.86209
## 48 69.97629
## 49 59.53415
## 57 57.65260
## 59 56.91763
## 60 57.43848
## 79 68.29692
## 80 67.99165
## 82 80.00336
## 105 73.56737
## 108 72.97306
## 115 83.84505
## 124 82.45711
## 129 79.09504
## 130 79.48500
## 136 76.26041
## 137 76.27300
## 151 71.50479
## 156 69.37623
## 157 69.71964
## 159 68.41937
## 164 73.99311
## 168 74.78687
## 174 74.64601
## 176 68.77127
## 182 75.66910
## 184 75.74653
## 186 75.71337
## 190 75.01001
## 193 70.50388
## 194 68.94431
## 201 67.91196
## 204 68.89757
## 206 65.57496
## 209 77.69239
## 210 77.53767
## 213 77.11635
## 218 75.52773
## 221 70.60495
## 223 68.79800
## 226 76.74264
## 232 75.42076
## 240 74.11138
## 242 79.62985
## 247 79.08562
## 258 72.84780
## 259 73.15668
## 264 74.15598
## 278 58.90128
## 285 56.39172
## 287 56.08597
## 288 56.36596
## 289 68.23991
## 296 61.39419
## 297 61.92013
## 298 61.65784
## 306 75.85674
## 307 75.22626
## 312 72.02436
## 318 72.29254
## 338 63.23719
## 339 60.99163
## 345 58.61322
## 351 54.48637
## 356 76.81192
## 368 76.07938
## 371 76.59082
## 375 75.88854
## 386 75.94112
## 402 60.90420
## 406 61.19793
## 409 58.76365
## 415 50.79987
## 418 62.59232
## 419 61.56918
## 426 56.50613
## 429 53.79469
## 430 53.56022
## 446 56.55637
## 448 56.83985
## 450 70.34551
## 451 70.14270
## 452 67.95593
## 453 66.91956
## 459 65.02777
## 460 65.37016
## 465 69.55411
## 468 64.36302
## 478 55.18980
## 480 53.30017
## 482 57.65236
## 492 53.45678
## 493 54.07134
## 503 79.63121
## 505 80.67652
## 509 79.50925
## 511 79.46527
## 513 52.87530
## 516 51.10272
## 518 50.79731
## 523 48.85853
## 527 50.61146
## 532 54.66459
## 537 51.60181
## 545 79.66309
## 555 77.43983
## 556 76.60600
## 559 77.28857
## 577 74.58519
## 580 75.30146
## 596 62.03666
## 601 65.80368
## 603 65.66422
## 614 57.61624
## 626 75.39633
## 627 75.72007
## 635 74.71675
## 642 78.08990
## 645 77.58596
## 646 77.19050
## 655 73.69398
## 658 76.11105
## 665 77.99008
## 673 74.17941
## 686 76.81145
## 698 73.97012
## 699 74.01068
## 701 73.45732
## 720 69.55470
## 729 61.38720
## 732 58.19061
## 751 80.12571
## 752 78.68092
## 758 56.85955
## 760 57.19318
## 767 53.03872
## 771 70.71457
## 774 69.86324
## 788 75.20178
## 798 69.77258
## 807 73.10832
## 816 72.11862
## 822 71.13176
## 823 70.52063
## 825 70.65935
## 835 56.51264
## 840 54.89046
## 847 57.48048
## 853 62.63218
## 858 59.80014
## 859 59.15821
## 864 51.44088
## 872 76.49477
## 876 75.18618
## 878 74.69076
## 881 75.33519
## 884 61.30860
## 894 52.79707
## 898 49.74979
## 899 77.22721
## 902 74.81497
## 904 75.87496
## 906 75.53618
## 911 73.81689
## 922 80.56039
## 925 80.89492
## 926 82.00550
## 931 80.75524
## 934 79.96054
## 935 79.15860
## 954 57.08582
## 958 55.11058
## 960 54.28534
## 961 55.02049
## 971 58.99159
## 978 57.92349
## 979 75.97328
## 988 74.19307
## 991 71.41419
## 994 65.38296
## 997 79.95217
## 1002 79.80209
## 1006 79.15642
## 1011 65.26283
## 1014 63.36983
## 1022 55.66507
## 1027 79.46687
## 1035 80.78548
## 1036 79.69687
## 1039 78.79284
## 1041 77.51639
## 1047 76.46570
## 1050 71.63639
## 1051 71.04601
## 1058 70.23765
## 1062 69.14854
## 1066 68.63565
## 1074 67.40803
## 1079 55.24686
## 1080 54.88630
## 1089 55.01669
## 1093 54.74538
## 1094 54.25291
## 1096 55.32681
## 1099 54.17412
## 1103 50.30225
## 1105 51.00763
## 1111 68.55036
## 1115 63.86326
## 1118 62.46780
## 1119 60.57282
## 1124 60.01234
## 1137 54.18087
## 1139 70.50397
## 1141 69.67113
## 1146 67.31252
## 1147 66.75425
## 1152 63.58881
## 1157 78.75479
## 1158 78.60366
## 1161 78.34458
## 1164 77.36230
## 1166 76.51831
## 1168 75.60326
## 1171 81.23760
## 1172 79.75934
## 1175 79.96260
## 1176 82.33061
## 1178 82.51633
## 1180 81.51172
## 1187 67.39080
## 1199 61.08870
## 1200 60.87914
## 1210 66.83594
## 1213 67.88944
## 1215 67.44605
## 1226 73.04880
## 1228 72.36076
## 1230 72.62885
## 1232 72.38625
## 1234 72.03076
## 1237 68.90902
## 1242 68.63457
## 1251 82.16561
## 1252 82.07166
## 1271 79.19135
## 1273 79.18464
## 1282 77.30669
## 1290 79.35242
## 1302 69.84888
## 1308 66.56688
## 1322 79.22749
## 1329 78.17281
## 1343 74.21580
## 1350 77.62766
## 1355 76.50115
## 1365 59.37025
## 1367 60.04142
## 1372 52.81547
## 1375 50.82195
## 1384 73.67408
## 1391 65.54119
## 1392 66.96738
## 1396 74.57534
## 1404 76.26940
## 1413 72.80982
## 1415 71.50321
## 1417 73.15401
## 1420 72.81368
## 1425 73.23601
## 1433 65.83066
## 1445 76.54398
## 1453 78.45476
## 1458 76.03037
## 1463 73.36020
## 1466 72.39761
## 1470 66.95293
## 1471 67.66549
## 1479 56.91685
## 1483 51.88719
## 1491 59.45380
## 1499 54.83838
## 1505 54.93741
## 1511 73.56118
## 1513 74.51287
## 1515 74.71853
## 1518 74.75980
## 1519 75.28303
## 1522 74.74668
## 1526 75.84655
## 1531 77.18502
## 1535 76.13435
## 1537 75.48656
## 1540 78.88769
## 1542 78.20594
## 1543 79.30010
## 1549 77.77980
## 1551 77.97250
## 1553 77.67891
## 1567 58.66633
## 1572 56.83529
## 1573 55.23537
## 1581 50.75468
## 1582 50.88396
## 1586 49.27009
## 1589 73.59522
## 1593 73.62788
## 1597 73.14137
## 1607 72.82539
## 1618 71.75491
## 1633 53.07771
## 1639 79.40319
## 1649 77.00841
## 1650 76.78079
## 1659 57.94167
## 1666 58.65878
## 1674 75.35048
## 1676 74.86129
## 1678 74.54481
## 1687 76.16327
## 1690 76.05390
## 1691 76.16257
## 1693 76.15480
## 1698 74.52745
## 1703 73.96819
## 1708 72.78940
## 1709 71.62192
## 1714 71.79002
## 1723 75.24458
## 1725 74.41353
## 1727 73.82537
## 1734 75.70600
## 1738 77.61464
## 1743 75.31121
## 1748 65.88058
## 1760 70.78410
## 1763 69.87710
## 1764 69.40873
## 1766 55.36656
## 1776 50.88001
## 1777 50.86492
## 1784 62.72696
## 1788 61.41031
## 1795 60.19517
## 1799 60.99879
## 1801 58.13598
## 1818 67.40385
## 1826 65.61186
## 1832 82.57702
## 1833 82.07143
## 1848 83.43555
## 1854 81.54683
## 1856 81.28123
## 1858 79.07295
## 1861 78.42670
## 1862 73.79637
## 1868 71.70007
## 1878 60.64877
## 1885 55.37112
## 1890 52.61720
## 1894 56.04322
## 1898 54.88220
## 1905 52.81084
## 1911 81.41852
## 1913 80.24967
## 1916 81.95790
## 1917 80.46941
## 1919 82.01928
## 1928 74.68506
## 1933 74.47882
## 1936 72.65232
## 1940 73.20363
## 1942 66.47158
## 1943 67.57527
## 1944 65.80757
## 1957 62.92699
## 1960 73.85796
## 1962 74.17796
## 1965 76.22421
## 1968 71.78379
## 1972 76.16312
## 1973 74.03274
## 1978 61.71004
## 1981 60.33010
## 1982 60.57749
## 1987 57.82872
## 1988 58.33144
## 1989 57.61545
## 1990 57.60556
## 1992 71.35454
## 1997 74.19150
## 2013 72.85783
## 2023 70.83928
## 2028 73.24052
## 2034 72.99517
## 2044 78.58750
## 2047 76.37051
## 2058 79.80083
## 2059 78.84506
## 2063 78.79821
## 2064 77.53272
## 2066 77.26810
## 2069 78.62387
## 2070 77.86107
## 2073 75.40782
## 2083 76.11660
## 2086 73.88888
## 2092 75.12233
## 2094 74.46614
## 2095 74.39979
## 2097 75.03093
## 2103 73.99501
## 2105 71.19793
## 2109 71.81766
## 2114 74.54117
## 2124 75.37228
## 2125 77.74724
## 2135 74.30055
## 2153 65.14648
## 2154 65.20816
## 2157 61.49394
## 2167 51.85972
## 2176 73.81467
## 2178 71.25844
## 2180 70.57970
## 2181 68.14025
## 2183 70.55800
## 2200 63.11184
## 2203 72.60637
## 2211 72.32554
## 2220 69.03982
## 2221 64.98852
## 2227 64.14739
## 2232 60.79124
## 2239 74.99567
## 2248 73.46745
## 2249 73.03622
## 2256 61.67465
## 2258 60.95151
## 2268 76.43792
## 2271 75.36668
## 2278 74.72811
## 2279 75.60905
## 2281 74.06250
## 2287 74.55079
## 2290 75.81230
## 2299 61.08206
## 2306 55.69103
## 2310 56.93909
## 2316 77.80976
## 2317 78.58515
## 2323 76.38819
## 2331 77.94135
## 2340 76.85232
## 2341 76.87114
## 2342 76.64147
## 2354 79.72118
## 2362 72.64387
## 2366 71.80706
## 2367 68.38340
## 2371 71.08510
## 2372 68.77401
## 2373 67.51534
## 2376 68.19068
## 2377 67.88946
## 2382 61.34600
## 2387 61.38671
## 2393 61.47270
## 2399 57.18471
## 2408 53.86808
## 2413 54.93225
## 2422 56.04085
## 2424 56.51490
## 2431 79.98573
## 2433 80.34702
## 2434 78.98351
## 2435 79.63864
## 2439 78.14410
## 2443 73.94768
## 2444 73.85914
## 2445 73.80544
## 2457 72.22228
## 2465 65.34800
## 2477 67.33926
## 2482 66.65024
## 2487 57.35935
## 2488 56.50260
## 2491 58.57560
## 2493 56.33145
## 2501 50.89404
## 2502 48.95950
## 2510 80.99026
## 2512 79.86687
## 2514 80.63407
## 2516 79.87535
## 2518 80.62376
## 2521 80.31691
## 2526 81.00702
## 2534 77.86487
## 2536 78.46888
## 2546 68.63360
## 2547 69.25685
## 2551 69.65846
## 2552 69.34732
## 2553 69.53944
## 2555 68.94708
## 2560 68.74060
## 2571 75.79362
## 2573 75.62126
## 2581 68.83205
## 2589 74.45050
## 2604 68.41235
## 2605 69.28158
## 2607 67.90513
## 2611 65.65429
## 2622 58.75733
## 2628 55.25533
## 2629 54.05078
## 2637 73.86940
## 2640 74.18828
## 2643 75.90395
## 2664 65.92786
## 2669 75.21351
## 2675 74.90331
## 2677 74.03319
## 2683 75.94349
## 2686 75.48790
## 2691 70.04140
## 2695 69.86840
## 2697 70.92398
## 2703 67.89668
## 2716 56.62387
## 2720 55.11144
## 2721 55.49390
## 2724 53.47347
## 2729 51.01863
## 2736 70.80682
## 2740 69.07944
## 2741 69.47736
## 2748 76.75885
## 2755 75.18894
## 2761 73.89355
## 2762 73.72997
## 2776 74.28485
## 2779 65.77646
## 2805 76.27514
## 2811 78.24547
## 2813 78.56469
## 2823 76.58712
## 2825 76.80081
## 2831 74.11609
## 2832 71.62497
## 2834 69.45426
## 2836 68.33655
## 2841 69.85779
## 2848 69.18885
## 2850 69.23409
## 2853 64.38059
## 2857 64.54653
## 2863 74.45297
## 2871 71.56684
## 2875 73.38086
## 2877 69.24940
## 2878 73.20412
## 2899 66.70666
## 2902 65.71903
## 2908 58.51361
## 2912 56.73322
## 2913 57.18364
## 2920 51.85048
## 2926 57.16869
## 2931 50.23588
## 2938 48.44372
MSPE = data.frame(Observed = validate$Life.expectancy,
Predicted = poly2log.interaction.model_Preds)
MSPE$Residual = MSPE$Observed - MSPE$Predicted
MSPE$SquaredResidual = MSPE$Residual^2
sqrt(mean(MSPE$SquaredResidual))
## [1] 3.671729
# RMSE of Poly7Log Model with interactions
poly7log.interaction.model_Preds = predict(poly7log.interaction.model, newdata = validate)
as.data.frame(poly2logmodel_Preds)
## poly2logmodel_Preds
## 1 65.36285
## 6 65.04255
## 7 64.57153
## 9 64.07558
## 10 63.57594
## 24 75.15340
## 28 74.49068
## 33 75.77933
## 35 74.73490
## 36 74.68665
## 42 72.62916
## 43 69.86209
## 48 69.97629
## 49 59.53415
## 57 57.65260
## 59 56.91763
## 60 57.43848
## 79 68.29692
## 80 67.99165
## 82 80.00336
## 105 73.56737
## 108 72.97306
## 115 83.84505
## 124 82.45711
## 129 79.09504
## 130 79.48500
## 136 76.26041
## 137 76.27300
## 151 71.50479
## 156 69.37623
## 157 69.71964
## 159 68.41937
## 164 73.99311
## 168 74.78687
## 174 74.64601
## 176 68.77127
## 182 75.66910
## 184 75.74653
## 186 75.71337
## 190 75.01001
## 193 70.50388
## 194 68.94431
## 201 67.91196
## 204 68.89757
## 206 65.57496
## 209 77.69239
## 210 77.53767
## 213 77.11635
## 218 75.52773
## 221 70.60495
## 223 68.79800
## 226 76.74264
## 232 75.42076
## 240 74.11138
## 242 79.62985
## 247 79.08562
## 258 72.84780
## 259 73.15668
## 264 74.15598
## 278 58.90128
## 285 56.39172
## 287 56.08597
## 288 56.36596
## 289 68.23991
## 296 61.39419
## 297 61.92013
## 298 61.65784
## 306 75.85674
## 307 75.22626
## 312 72.02436
## 318 72.29254
## 338 63.23719
## 339 60.99163
## 345 58.61322
## 351 54.48637
## 356 76.81192
## 368 76.07938
## 371 76.59082
## 375 75.88854
## 386 75.94112
## 402 60.90420
## 406 61.19793
## 409 58.76365
## 415 50.79987
## 418 62.59232
## 419 61.56918
## 426 56.50613
## 429 53.79469
## 430 53.56022
## 446 56.55637
## 448 56.83985
## 450 70.34551
## 451 70.14270
## 452 67.95593
## 453 66.91956
## 459 65.02777
## 460 65.37016
## 465 69.55411
## 468 64.36302
## 478 55.18980
## 480 53.30017
## 482 57.65236
## 492 53.45678
## 493 54.07134
## 503 79.63121
## 505 80.67652
## 509 79.50925
## 511 79.46527
## 513 52.87530
## 516 51.10272
## 518 50.79731
## 523 48.85853
## 527 50.61146
## 532 54.66459
## 537 51.60181
## 545 79.66309
## 555 77.43983
## 556 76.60600
## 559 77.28857
## 577 74.58519
## 580 75.30146
## 596 62.03666
## 601 65.80368
## 603 65.66422
## 614 57.61624
## 626 75.39633
## 627 75.72007
## 635 74.71675
## 642 78.08990
## 645 77.58596
## 646 77.19050
## 655 73.69398
## 658 76.11105
## 665 77.99008
## 673 74.17941
## 686 76.81145
## 698 73.97012
## 699 74.01068
## 701 73.45732
## 720 69.55470
## 729 61.38720
## 732 58.19061
## 751 80.12571
## 752 78.68092
## 758 56.85955
## 760 57.19318
## 767 53.03872
## 771 70.71457
## 774 69.86324
## 788 75.20178
## 798 69.77258
## 807 73.10832
## 816 72.11862
## 822 71.13176
## 823 70.52063
## 825 70.65935
## 835 56.51264
## 840 54.89046
## 847 57.48048
## 853 62.63218
## 858 59.80014
## 859 59.15821
## 864 51.44088
## 872 76.49477
## 876 75.18618
## 878 74.69076
## 881 75.33519
## 884 61.30860
## 894 52.79707
## 898 49.74979
## 899 77.22721
## 902 74.81497
## 904 75.87496
## 906 75.53618
## 911 73.81689
## 922 80.56039
## 925 80.89492
## 926 82.00550
## 931 80.75524
## 934 79.96054
## 935 79.15860
## 954 57.08582
## 958 55.11058
## 960 54.28534
## 961 55.02049
## 971 58.99159
## 978 57.92349
## 979 75.97328
## 988 74.19307
## 991 71.41419
## 994 65.38296
## 997 79.95217
## 1002 79.80209
## 1006 79.15642
## 1011 65.26283
## 1014 63.36983
## 1022 55.66507
## 1027 79.46687
## 1035 80.78548
## 1036 79.69687
## 1039 78.79284
## 1041 77.51639
## 1047 76.46570
## 1050 71.63639
## 1051 71.04601
## 1058 70.23765
## 1062 69.14854
## 1066 68.63565
## 1074 67.40803
## 1079 55.24686
## 1080 54.88630
## 1089 55.01669
## 1093 54.74538
## 1094 54.25291
## 1096 55.32681
## 1099 54.17412
## 1103 50.30225
## 1105 51.00763
## 1111 68.55036
## 1115 63.86326
## 1118 62.46780
## 1119 60.57282
## 1124 60.01234
## 1137 54.18087
## 1139 70.50397
## 1141 69.67113
## 1146 67.31252
## 1147 66.75425
## 1152 63.58881
## 1157 78.75479
## 1158 78.60366
## 1161 78.34458
## 1164 77.36230
## 1166 76.51831
## 1168 75.60326
## 1171 81.23760
## 1172 79.75934
## 1175 79.96260
## 1176 82.33061
## 1178 82.51633
## 1180 81.51172
## 1187 67.39080
## 1199 61.08870
## 1200 60.87914
## 1210 66.83594
## 1213 67.88944
## 1215 67.44605
## 1226 73.04880
## 1228 72.36076
## 1230 72.62885
## 1232 72.38625
## 1234 72.03076
## 1237 68.90902
## 1242 68.63457
## 1251 82.16561
## 1252 82.07166
## 1271 79.19135
## 1273 79.18464
## 1282 77.30669
## 1290 79.35242
## 1302 69.84888
## 1308 66.56688
## 1322 79.22749
## 1329 78.17281
## 1343 74.21580
## 1350 77.62766
## 1355 76.50115
## 1365 59.37025
## 1367 60.04142
## 1372 52.81547
## 1375 50.82195
## 1384 73.67408
## 1391 65.54119
## 1392 66.96738
## 1396 74.57534
## 1404 76.26940
## 1413 72.80982
## 1415 71.50321
## 1417 73.15401
## 1420 72.81368
## 1425 73.23601
## 1433 65.83066
## 1445 76.54398
## 1453 78.45476
## 1458 76.03037
## 1463 73.36020
## 1466 72.39761
## 1470 66.95293
## 1471 67.66549
## 1479 56.91685
## 1483 51.88719
## 1491 59.45380
## 1499 54.83838
## 1505 54.93741
## 1511 73.56118
## 1513 74.51287
## 1515 74.71853
## 1518 74.75980
## 1519 75.28303
## 1522 74.74668
## 1526 75.84655
## 1531 77.18502
## 1535 76.13435
## 1537 75.48656
## 1540 78.88769
## 1542 78.20594
## 1543 79.30010
## 1549 77.77980
## 1551 77.97250
## 1553 77.67891
## 1567 58.66633
## 1572 56.83529
## 1573 55.23537
## 1581 50.75468
## 1582 50.88396
## 1586 49.27009
## 1589 73.59522
## 1593 73.62788
## 1597 73.14137
## 1607 72.82539
## 1618 71.75491
## 1633 53.07771
## 1639 79.40319
## 1649 77.00841
## 1650 76.78079
## 1659 57.94167
## 1666 58.65878
## 1674 75.35048
## 1676 74.86129
## 1678 74.54481
## 1687 76.16327
## 1690 76.05390
## 1691 76.16257
## 1693 76.15480
## 1698 74.52745
## 1703 73.96819
## 1708 72.78940
## 1709 71.62192
## 1714 71.79002
## 1723 75.24458
## 1725 74.41353
## 1727 73.82537
## 1734 75.70600
## 1738 77.61464
## 1743 75.31121
## 1748 65.88058
## 1760 70.78410
## 1763 69.87710
## 1764 69.40873
## 1766 55.36656
## 1776 50.88001
## 1777 50.86492
## 1784 62.72696
## 1788 61.41031
## 1795 60.19517
## 1799 60.99879
## 1801 58.13598
## 1818 67.40385
## 1826 65.61186
## 1832 82.57702
## 1833 82.07143
## 1848 83.43555
## 1854 81.54683
## 1856 81.28123
## 1858 79.07295
## 1861 78.42670
## 1862 73.79637
## 1868 71.70007
## 1878 60.64877
## 1885 55.37112
## 1890 52.61720
## 1894 56.04322
## 1898 54.88220
## 1905 52.81084
## 1911 81.41852
## 1913 80.24967
## 1916 81.95790
## 1917 80.46941
## 1919 82.01928
## 1928 74.68506
## 1933 74.47882
## 1936 72.65232
## 1940 73.20363
## 1942 66.47158
## 1943 67.57527
## 1944 65.80757
## 1957 62.92699
## 1960 73.85796
## 1962 74.17796
## 1965 76.22421
## 1968 71.78379
## 1972 76.16312
## 1973 74.03274
## 1978 61.71004
## 1981 60.33010
## 1982 60.57749
## 1987 57.82872
## 1988 58.33144
## 1989 57.61545
## 1990 57.60556
## 1992 71.35454
## 1997 74.19150
## 2013 72.85783
## 2023 70.83928
## 2028 73.24052
## 2034 72.99517
## 2044 78.58750
## 2047 76.37051
## 2058 79.80083
## 2059 78.84506
## 2063 78.79821
## 2064 77.53272
## 2066 77.26810
## 2069 78.62387
## 2070 77.86107
## 2073 75.40782
## 2083 76.11660
## 2086 73.88888
## 2092 75.12233
## 2094 74.46614
## 2095 74.39979
## 2097 75.03093
## 2103 73.99501
## 2105 71.19793
## 2109 71.81766
## 2114 74.54117
## 2124 75.37228
## 2125 77.74724
## 2135 74.30055
## 2153 65.14648
## 2154 65.20816
## 2157 61.49394
## 2167 51.85972
## 2176 73.81467
## 2178 71.25844
## 2180 70.57970
## 2181 68.14025
## 2183 70.55800
## 2200 63.11184
## 2203 72.60637
## 2211 72.32554
## 2220 69.03982
## 2221 64.98852
## 2227 64.14739
## 2232 60.79124
## 2239 74.99567
## 2248 73.46745
## 2249 73.03622
## 2256 61.67465
## 2258 60.95151
## 2268 76.43792
## 2271 75.36668
## 2278 74.72811
## 2279 75.60905
## 2281 74.06250
## 2287 74.55079
## 2290 75.81230
## 2299 61.08206
## 2306 55.69103
## 2310 56.93909
## 2316 77.80976
## 2317 78.58515
## 2323 76.38819
## 2331 77.94135
## 2340 76.85232
## 2341 76.87114
## 2342 76.64147
## 2354 79.72118
## 2362 72.64387
## 2366 71.80706
## 2367 68.38340
## 2371 71.08510
## 2372 68.77401
## 2373 67.51534
## 2376 68.19068
## 2377 67.88946
## 2382 61.34600
## 2387 61.38671
## 2393 61.47270
## 2399 57.18471
## 2408 53.86808
## 2413 54.93225
## 2422 56.04085
## 2424 56.51490
## 2431 79.98573
## 2433 80.34702
## 2434 78.98351
## 2435 79.63864
## 2439 78.14410
## 2443 73.94768
## 2444 73.85914
## 2445 73.80544
## 2457 72.22228
## 2465 65.34800
## 2477 67.33926
## 2482 66.65024
## 2487 57.35935
## 2488 56.50260
## 2491 58.57560
## 2493 56.33145
## 2501 50.89404
## 2502 48.95950
## 2510 80.99026
## 2512 79.86687
## 2514 80.63407
## 2516 79.87535
## 2518 80.62376
## 2521 80.31691
## 2526 81.00702
## 2534 77.86487
## 2536 78.46888
## 2546 68.63360
## 2547 69.25685
## 2551 69.65846
## 2552 69.34732
## 2553 69.53944
## 2555 68.94708
## 2560 68.74060
## 2571 75.79362
## 2573 75.62126
## 2581 68.83205
## 2589 74.45050
## 2604 68.41235
## 2605 69.28158
## 2607 67.90513
## 2611 65.65429
## 2622 58.75733
## 2628 55.25533
## 2629 54.05078
## 2637 73.86940
## 2640 74.18828
## 2643 75.90395
## 2664 65.92786
## 2669 75.21351
## 2675 74.90331
## 2677 74.03319
## 2683 75.94349
## 2686 75.48790
## 2691 70.04140
## 2695 69.86840
## 2697 70.92398
## 2703 67.89668
## 2716 56.62387
## 2720 55.11144
## 2721 55.49390
## 2724 53.47347
## 2729 51.01863
## 2736 70.80682
## 2740 69.07944
## 2741 69.47736
## 2748 76.75885
## 2755 75.18894
## 2761 73.89355
## 2762 73.72997
## 2776 74.28485
## 2779 65.77646
## 2805 76.27514
## 2811 78.24547
## 2813 78.56469
## 2823 76.58712
## 2825 76.80081
## 2831 74.11609
## 2832 71.62497
## 2834 69.45426
## 2836 68.33655
## 2841 69.85779
## 2848 69.18885
## 2850 69.23409
## 2853 64.38059
## 2857 64.54653
## 2863 74.45297
## 2871 71.56684
## 2875 73.38086
## 2877 69.24940
## 2878 73.20412
## 2899 66.70666
## 2902 65.71903
## 2908 58.51361
## 2912 56.73322
## 2913 57.18364
## 2920 51.85048
## 2926 57.16869
## 2931 50.23588
## 2938 48.44372
MSPE = data.frame(Observed = validate$Life.expectancy,
Predicted = poly7log.interaction.model_Preds)
MSPE$Residual = MSPE$Observed - MSPE$Predicted
MSPE$SquaredResidual = MSPE$Residual^2
sqrt(mean(MSPE$SquaredResidual))
## [1] 3.533711
# RMSE of Poly7Log Model with Categorical variable Status added (not as interaction)
status.poly7logmodel_Preds = predict(status.poly7logmodel, newdata = validate)
as.data.frame(poly2logmodel_Preds)
## poly2logmodel_Preds
## 1 65.36285
## 6 65.04255
## 7 64.57153
## 9 64.07558
## 10 63.57594
## 24 75.15340
## 28 74.49068
## 33 75.77933
## 35 74.73490
## 36 74.68665
## 42 72.62916
## 43 69.86209
## 48 69.97629
## 49 59.53415
## 57 57.65260
## 59 56.91763
## 60 57.43848
## 79 68.29692
## 80 67.99165
## 82 80.00336
## 105 73.56737
## 108 72.97306
## 115 83.84505
## 124 82.45711
## 129 79.09504
## 130 79.48500
## 136 76.26041
## 137 76.27300
## 151 71.50479
## 156 69.37623
## 157 69.71964
## 159 68.41937
## 164 73.99311
## 168 74.78687
## 174 74.64601
## 176 68.77127
## 182 75.66910
## 184 75.74653
## 186 75.71337
## 190 75.01001
## 193 70.50388
## 194 68.94431
## 201 67.91196
## 204 68.89757
## 206 65.57496
## 209 77.69239
## 210 77.53767
## 213 77.11635
## 218 75.52773
## 221 70.60495
## 223 68.79800
## 226 76.74264
## 232 75.42076
## 240 74.11138
## 242 79.62985
## 247 79.08562
## 258 72.84780
## 259 73.15668
## 264 74.15598
## 278 58.90128
## 285 56.39172
## 287 56.08597
## 288 56.36596
## 289 68.23991
## 296 61.39419
## 297 61.92013
## 298 61.65784
## 306 75.85674
## 307 75.22626
## 312 72.02436
## 318 72.29254
## 338 63.23719
## 339 60.99163
## 345 58.61322
## 351 54.48637
## 356 76.81192
## 368 76.07938
## 371 76.59082
## 375 75.88854
## 386 75.94112
## 402 60.90420
## 406 61.19793
## 409 58.76365
## 415 50.79987
## 418 62.59232
## 419 61.56918
## 426 56.50613
## 429 53.79469
## 430 53.56022
## 446 56.55637
## 448 56.83985
## 450 70.34551
## 451 70.14270
## 452 67.95593
## 453 66.91956
## 459 65.02777
## 460 65.37016
## 465 69.55411
## 468 64.36302
## 478 55.18980
## 480 53.30017
## 482 57.65236
## 492 53.45678
## 493 54.07134
## 503 79.63121
## 505 80.67652
## 509 79.50925
## 511 79.46527
## 513 52.87530
## 516 51.10272
## 518 50.79731
## 523 48.85853
## 527 50.61146
## 532 54.66459
## 537 51.60181
## 545 79.66309
## 555 77.43983
## 556 76.60600
## 559 77.28857
## 577 74.58519
## 580 75.30146
## 596 62.03666
## 601 65.80368
## 603 65.66422
## 614 57.61624
## 626 75.39633
## 627 75.72007
## 635 74.71675
## 642 78.08990
## 645 77.58596
## 646 77.19050
## 655 73.69398
## 658 76.11105
## 665 77.99008
## 673 74.17941
## 686 76.81145
## 698 73.97012
## 699 74.01068
## 701 73.45732
## 720 69.55470
## 729 61.38720
## 732 58.19061
## 751 80.12571
## 752 78.68092
## 758 56.85955
## 760 57.19318
## 767 53.03872
## 771 70.71457
## 774 69.86324
## 788 75.20178
## 798 69.77258
## 807 73.10832
## 816 72.11862
## 822 71.13176
## 823 70.52063
## 825 70.65935
## 835 56.51264
## 840 54.89046
## 847 57.48048
## 853 62.63218
## 858 59.80014
## 859 59.15821
## 864 51.44088
## 872 76.49477
## 876 75.18618
## 878 74.69076
## 881 75.33519
## 884 61.30860
## 894 52.79707
## 898 49.74979
## 899 77.22721
## 902 74.81497
## 904 75.87496
## 906 75.53618
## 911 73.81689
## 922 80.56039
## 925 80.89492
## 926 82.00550
## 931 80.75524
## 934 79.96054
## 935 79.15860
## 954 57.08582
## 958 55.11058
## 960 54.28534
## 961 55.02049
## 971 58.99159
## 978 57.92349
## 979 75.97328
## 988 74.19307
## 991 71.41419
## 994 65.38296
## 997 79.95217
## 1002 79.80209
## 1006 79.15642
## 1011 65.26283
## 1014 63.36983
## 1022 55.66507
## 1027 79.46687
## 1035 80.78548
## 1036 79.69687
## 1039 78.79284
## 1041 77.51639
## 1047 76.46570
## 1050 71.63639
## 1051 71.04601
## 1058 70.23765
## 1062 69.14854
## 1066 68.63565
## 1074 67.40803
## 1079 55.24686
## 1080 54.88630
## 1089 55.01669
## 1093 54.74538
## 1094 54.25291
## 1096 55.32681
## 1099 54.17412
## 1103 50.30225
## 1105 51.00763
## 1111 68.55036
## 1115 63.86326
## 1118 62.46780
## 1119 60.57282
## 1124 60.01234
## 1137 54.18087
## 1139 70.50397
## 1141 69.67113
## 1146 67.31252
## 1147 66.75425
## 1152 63.58881
## 1157 78.75479
## 1158 78.60366
## 1161 78.34458
## 1164 77.36230
## 1166 76.51831
## 1168 75.60326
## 1171 81.23760
## 1172 79.75934
## 1175 79.96260
## 1176 82.33061
## 1178 82.51633
## 1180 81.51172
## 1187 67.39080
## 1199 61.08870
## 1200 60.87914
## 1210 66.83594
## 1213 67.88944
## 1215 67.44605
## 1226 73.04880
## 1228 72.36076
## 1230 72.62885
## 1232 72.38625
## 1234 72.03076
## 1237 68.90902
## 1242 68.63457
## 1251 82.16561
## 1252 82.07166
## 1271 79.19135
## 1273 79.18464
## 1282 77.30669
## 1290 79.35242
## 1302 69.84888
## 1308 66.56688
## 1322 79.22749
## 1329 78.17281
## 1343 74.21580
## 1350 77.62766
## 1355 76.50115
## 1365 59.37025
## 1367 60.04142
## 1372 52.81547
## 1375 50.82195
## 1384 73.67408
## 1391 65.54119
## 1392 66.96738
## 1396 74.57534
## 1404 76.26940
## 1413 72.80982
## 1415 71.50321
## 1417 73.15401
## 1420 72.81368
## 1425 73.23601
## 1433 65.83066
## 1445 76.54398
## 1453 78.45476
## 1458 76.03037
## 1463 73.36020
## 1466 72.39761
## 1470 66.95293
## 1471 67.66549
## 1479 56.91685
## 1483 51.88719
## 1491 59.45380
## 1499 54.83838
## 1505 54.93741
## 1511 73.56118
## 1513 74.51287
## 1515 74.71853
## 1518 74.75980
## 1519 75.28303
## 1522 74.74668
## 1526 75.84655
## 1531 77.18502
## 1535 76.13435
## 1537 75.48656
## 1540 78.88769
## 1542 78.20594
## 1543 79.30010
## 1549 77.77980
## 1551 77.97250
## 1553 77.67891
## 1567 58.66633
## 1572 56.83529
## 1573 55.23537
## 1581 50.75468
## 1582 50.88396
## 1586 49.27009
## 1589 73.59522
## 1593 73.62788
## 1597 73.14137
## 1607 72.82539
## 1618 71.75491
## 1633 53.07771
## 1639 79.40319
## 1649 77.00841
## 1650 76.78079
## 1659 57.94167
## 1666 58.65878
## 1674 75.35048
## 1676 74.86129
## 1678 74.54481
## 1687 76.16327
## 1690 76.05390
## 1691 76.16257
## 1693 76.15480
## 1698 74.52745
## 1703 73.96819
## 1708 72.78940
## 1709 71.62192
## 1714 71.79002
## 1723 75.24458
## 1725 74.41353
## 1727 73.82537
## 1734 75.70600
## 1738 77.61464
## 1743 75.31121
## 1748 65.88058
## 1760 70.78410
## 1763 69.87710
## 1764 69.40873
## 1766 55.36656
## 1776 50.88001
## 1777 50.86492
## 1784 62.72696
## 1788 61.41031
## 1795 60.19517
## 1799 60.99879
## 1801 58.13598
## 1818 67.40385
## 1826 65.61186
## 1832 82.57702
## 1833 82.07143
## 1848 83.43555
## 1854 81.54683
## 1856 81.28123
## 1858 79.07295
## 1861 78.42670
## 1862 73.79637
## 1868 71.70007
## 1878 60.64877
## 1885 55.37112
## 1890 52.61720
## 1894 56.04322
## 1898 54.88220
## 1905 52.81084
## 1911 81.41852
## 1913 80.24967
## 1916 81.95790
## 1917 80.46941
## 1919 82.01928
## 1928 74.68506
## 1933 74.47882
## 1936 72.65232
## 1940 73.20363
## 1942 66.47158
## 1943 67.57527
## 1944 65.80757
## 1957 62.92699
## 1960 73.85796
## 1962 74.17796
## 1965 76.22421
## 1968 71.78379
## 1972 76.16312
## 1973 74.03274
## 1978 61.71004
## 1981 60.33010
## 1982 60.57749
## 1987 57.82872
## 1988 58.33144
## 1989 57.61545
## 1990 57.60556
## 1992 71.35454
## 1997 74.19150
## 2013 72.85783
## 2023 70.83928
## 2028 73.24052
## 2034 72.99517
## 2044 78.58750
## 2047 76.37051
## 2058 79.80083
## 2059 78.84506
## 2063 78.79821
## 2064 77.53272
## 2066 77.26810
## 2069 78.62387
## 2070 77.86107
## 2073 75.40782
## 2083 76.11660
## 2086 73.88888
## 2092 75.12233
## 2094 74.46614
## 2095 74.39979
## 2097 75.03093
## 2103 73.99501
## 2105 71.19793
## 2109 71.81766
## 2114 74.54117
## 2124 75.37228
## 2125 77.74724
## 2135 74.30055
## 2153 65.14648
## 2154 65.20816
## 2157 61.49394
## 2167 51.85972
## 2176 73.81467
## 2178 71.25844
## 2180 70.57970
## 2181 68.14025
## 2183 70.55800
## 2200 63.11184
## 2203 72.60637
## 2211 72.32554
## 2220 69.03982
## 2221 64.98852
## 2227 64.14739
## 2232 60.79124
## 2239 74.99567
## 2248 73.46745
## 2249 73.03622
## 2256 61.67465
## 2258 60.95151
## 2268 76.43792
## 2271 75.36668
## 2278 74.72811
## 2279 75.60905
## 2281 74.06250
## 2287 74.55079
## 2290 75.81230
## 2299 61.08206
## 2306 55.69103
## 2310 56.93909
## 2316 77.80976
## 2317 78.58515
## 2323 76.38819
## 2331 77.94135
## 2340 76.85232
## 2341 76.87114
## 2342 76.64147
## 2354 79.72118
## 2362 72.64387
## 2366 71.80706
## 2367 68.38340
## 2371 71.08510
## 2372 68.77401
## 2373 67.51534
## 2376 68.19068
## 2377 67.88946
## 2382 61.34600
## 2387 61.38671
## 2393 61.47270
## 2399 57.18471
## 2408 53.86808
## 2413 54.93225
## 2422 56.04085
## 2424 56.51490
## 2431 79.98573
## 2433 80.34702
## 2434 78.98351
## 2435 79.63864
## 2439 78.14410
## 2443 73.94768
## 2444 73.85914
## 2445 73.80544
## 2457 72.22228
## 2465 65.34800
## 2477 67.33926
## 2482 66.65024
## 2487 57.35935
## 2488 56.50260
## 2491 58.57560
## 2493 56.33145
## 2501 50.89404
## 2502 48.95950
## 2510 80.99026
## 2512 79.86687
## 2514 80.63407
## 2516 79.87535
## 2518 80.62376
## 2521 80.31691
## 2526 81.00702
## 2534 77.86487
## 2536 78.46888
## 2546 68.63360
## 2547 69.25685
## 2551 69.65846
## 2552 69.34732
## 2553 69.53944
## 2555 68.94708
## 2560 68.74060
## 2571 75.79362
## 2573 75.62126
## 2581 68.83205
## 2589 74.45050
## 2604 68.41235
## 2605 69.28158
## 2607 67.90513
## 2611 65.65429
## 2622 58.75733
## 2628 55.25533
## 2629 54.05078
## 2637 73.86940
## 2640 74.18828
## 2643 75.90395
## 2664 65.92786
## 2669 75.21351
## 2675 74.90331
## 2677 74.03319
## 2683 75.94349
## 2686 75.48790
## 2691 70.04140
## 2695 69.86840
## 2697 70.92398
## 2703 67.89668
## 2716 56.62387
## 2720 55.11144
## 2721 55.49390
## 2724 53.47347
## 2729 51.01863
## 2736 70.80682
## 2740 69.07944
## 2741 69.47736
## 2748 76.75885
## 2755 75.18894
## 2761 73.89355
## 2762 73.72997
## 2776 74.28485
## 2779 65.77646
## 2805 76.27514
## 2811 78.24547
## 2813 78.56469
## 2823 76.58712
## 2825 76.80081
## 2831 74.11609
## 2832 71.62497
## 2834 69.45426
## 2836 68.33655
## 2841 69.85779
## 2848 69.18885
## 2850 69.23409
## 2853 64.38059
## 2857 64.54653
## 2863 74.45297
## 2871 71.56684
## 2875 73.38086
## 2877 69.24940
## 2878 73.20412
## 2899 66.70666
## 2902 65.71903
## 2908 58.51361
## 2912 56.73322
## 2913 57.18364
## 2920 51.85048
## 2926 57.16869
## 2931 50.23588
## 2938 48.44372
MSPE = data.frame(Observed = validate$Life.expectancy,
Predicted = status.poly7logmodel_Preds)
MSPE$Residual = MSPE$Observed - MSPE$Predicted
MSPE$SquaredResidual = MSPE$Residual^2
sqrt(mean(MSPE$SquaredResidual))
## [1] 3.702815
KNN Model Predictions
library(caret)
fit_cont1 = trainControl(method = "repeatedcv", number = 10, repeats = 1)
set.seed(1364)
knnfit1 = train(Life.expectancy~Adult.Mortality + infant.deaths + Alcohol + percentage.expenditure + Measles + BMI + under.five.deaths + Polio + Total.expenditure + Diphtheria + HIV.AIDS + thinness..1.19.years + thinness.5.9.years + Income.composition.of.resources + Schooling + GDP, data =training, method = "knn", trControl = fit_cont1, tuneGrid = expand.grid(k = c(1:30)))
plot(knnfit1)
updateval = validate[,c("Life.expectancy", "Adult.Mortality", "infant.deaths", "Alcohol", "percentage.expenditure", "Measles", "BMI", "under.five.deaths", "Polio", "Total.expenditure", "Diphtheria", "HIV.AIDS", "thinness..1.19.years","thinness.5.9.years", "Income.composition.of.resources", "Schooling", "GDP")]
prediction = predict(knnfit1, newdata = updateval)
MSPE = data.frame(Observed = validate$Life.expectancy,
Predicted = prediction)
MSPE$Residual = MSPE$Observed - MSPE$Predicted
MSPE$SquaredResidual = MSPE$Residual^2
sqrt(mean(MSPE$SquaredResidual))
## [1] 5.595665
#cf = confusionMatrix(prediction,updateval$Life.expectancy))
#cf